enable_if.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // (C) Copyright David Abrahams 2002.
  2. // (C) Copyright Jeremy Siek 2002.
  3. // (C) Copyright Thomas Witt 2002.
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_ENABLE_IF_23022003THW_HPP
  8. #define BOOST_ENABLE_IF_23022003THW_HPP
  9. #include <boost/config.hpp>
  10. #include <boost/iterator/detail/config_def.hpp>
  11. #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_IS_CONVERTIBLE)
  12. #include <boost/type_traits/type_identity.hpp>
  13. #endif
  14. //
  15. // Boost iterators uses its own enable_if cause we need
  16. // special semantics for deficient compilers.
  17. // 23/02/03 thw
  18. //
  19. namespace boost
  20. {
  21. namespace iterators
  22. {
  23. //
  24. // Base machinery for all kinds of enable if
  25. //
  26. template<bool>
  27. struct enabled
  28. {
  29. template<typename T>
  30. struct base
  31. {
  32. typedef T type;
  33. };
  34. };
  35. //
  36. // For compilers that don't support "Substitution Failure Is Not An Error"
  37. // enable_if falls back to always enabled. See comments
  38. // on operator implementation for consequences.
  39. //
  40. template<>
  41. struct enabled<false>
  42. {
  43. template<typename T>
  44. struct base
  45. {
  46. #ifdef BOOST_NO_SFINAE
  47. typedef T type;
  48. // This way to do it would give a nice error message containing
  49. // invalid overload, but has the big disadvantage that
  50. // there is no reference to user code in the error message.
  51. //
  52. // struct invalid_overload;
  53. // typedef invalid_overload type;
  54. //
  55. #endif
  56. };
  57. };
  58. template <class Cond,
  59. class Return>
  60. struct enable_if
  61. # if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE)
  62. : enabled<(Cond::value)>::template base<Return>
  63. # else
  64. : boost::type_identity<Return>
  65. # endif
  66. {
  67. };
  68. } // namespace iterators
  69. } // namespace boost
  70. #include <boost/iterator/detail/config_undef.hpp>
  71. #endif // BOOST_ENABLE_IF_23022003THW_HPP