enable_if.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Boost enable_if library
  2. // Copyright 2003 (c) The Trustees of Indiana University.
  3. // Use, modification, and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
  7. // Jeremiah Willcock (jewillco at osl.iu.edu)
  8. // Andrew Lumsdaine (lums at osl.iu.edu)
  9. #ifndef BOOST_UTILITY_ENABLE_IF_HPP
  10. #define BOOST_UTILITY_ENABLE_IF_HPP
  11. #include "boost/config.hpp"
  12. // Even the definition of enable_if causes problems on some compilers,
  13. // so it's macroed out for all compilers that do not support SFINAE
  14. #ifndef BOOST_NO_SFINAE
  15. namespace boost
  16. {
  17. template <bool B, class T = void>
  18. struct enable_if_c {
  19. typedef T type;
  20. };
  21. template <class T>
  22. struct enable_if_c<false, T> {};
  23. template <class Cond, class T = void>
  24. struct enable_if : public enable_if_c<Cond::value, T> {};
  25. template <bool B, class T>
  26. struct lazy_enable_if_c {
  27. typedef typename T::type type;
  28. };
  29. template <class T>
  30. struct lazy_enable_if_c<false, T> {};
  31. template <class Cond, class T>
  32. struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
  33. template <bool B, class T = void>
  34. struct disable_if_c {
  35. typedef T type;
  36. };
  37. template <class T>
  38. struct disable_if_c<true, T> {};
  39. template <class Cond, class T = void>
  40. struct disable_if : public disable_if_c<Cond::value, T> {};
  41. template <bool B, class T>
  42. struct lazy_disable_if_c {
  43. typedef typename T::type type;
  44. };
  45. template <class T>
  46. struct lazy_disable_if_c<true, T> {};
  47. template <class Cond, class T>
  48. struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
  49. } // namespace boost
  50. #else
  51. namespace boost {
  52. namespace detail { typedef void enable_if_default_T; }
  53. template <typename T>
  54. struct enable_if_does_not_work_on_this_compiler;
  55. template <bool B, class T = detail::enable_if_default_T>
  56. struct enable_if_c : enable_if_does_not_work_on_this_compiler<T>
  57. { };
  58. template <bool B, class T = detail::enable_if_default_T>
  59. struct disable_if_c : enable_if_does_not_work_on_this_compiler<T>
  60. { };
  61. template <bool B, class T = detail::enable_if_default_T>
  62. struct lazy_enable_if_c : enable_if_does_not_work_on_this_compiler<T>
  63. { };
  64. template <bool B, class T = detail::enable_if_default_T>
  65. struct lazy_disable_if_c : enable_if_does_not_work_on_this_compiler<T>
  66. { };
  67. template <class Cond, class T = detail::enable_if_default_T>
  68. struct enable_if : enable_if_does_not_work_on_this_compiler<T>
  69. { };
  70. template <class Cond, class T = detail::enable_if_default_T>
  71. struct disable_if : enable_if_does_not_work_on_this_compiler<T>
  72. { };
  73. template <class Cond, class T = detail::enable_if_default_T>
  74. struct lazy_enable_if : enable_if_does_not_work_on_this_compiler<T>
  75. { };
  76. template <class Cond, class T = detail::enable_if_default_T>
  77. struct lazy_disable_if : enable_if_does_not_work_on_this_compiler<T>
  78. { };
  79. } // namespace boost
  80. #endif // BOOST_NO_SFINAE
  81. #endif