enable_if.hpp 1.9 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/detail/workaround.hpp>
  10. #include <boost/mpl/identity.hpp>
  11. #include <boost/iterator/detail/config_def.hpp>
  12. //
  13. // Boost iterators uses its own enable_if cause we need
  14. // special semantics for deficient compilers.
  15. // 23/02/03 thw
  16. //
  17. namespace boost
  18. {
  19. namespace iterators
  20. {
  21. //
  22. // Base machinery for all kinds of enable if
  23. //
  24. template<bool>
  25. struct enabled
  26. {
  27. template<typename T>
  28. struct base
  29. {
  30. typedef T type;
  31. };
  32. };
  33. //
  34. // For compilers that don't support "Substitution Failure Is Not An Error"
  35. // enable_if falls back to always enabled. See comments
  36. // on operator implementation for consequences.
  37. //
  38. template<>
  39. struct enabled<false>
  40. {
  41. template<typename T>
  42. struct base
  43. {
  44. #ifdef BOOST_NO_SFINAE
  45. typedef T type;
  46. // This way to do it would give a nice error message containing
  47. // invalid overload, but has the big disadvantage that
  48. // there is no reference to user code in the error message.
  49. //
  50. // struct invalid_overload;
  51. // typedef invalid_overload type;
  52. //
  53. #endif
  54. };
  55. };
  56. template <class Cond,
  57. class Return>
  58. struct enable_if
  59. # if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE)
  60. : enabled<(Cond::value)>::template base<Return>
  61. # else
  62. : mpl::identity<Return>
  63. # endif
  64. {
  65. };
  66. } // namespace iterators
  67. } // namespace boost
  68. #include <boost/iterator/detail/config_undef.hpp>
  69. #endif // BOOST_ENABLE_IF_23022003THW_HPP