enable_if.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_CORE_ENABLE_IF_HPP
  10. #define BOOST_CORE_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<typename T, typename R=void>
  18. struct enable_if_has_type
  19. {
  20. typedef R type;
  21. };
  22. template <bool B, class T = void>
  23. struct enable_if_c {
  24. typedef T type;
  25. };
  26. template <class T>
  27. struct enable_if_c<false, T> {};
  28. template <class Cond, class T = void>
  29. struct enable_if : public enable_if_c<Cond::value, T> {};
  30. template <bool B, class T>
  31. struct lazy_enable_if_c {
  32. typedef typename T::type type;
  33. };
  34. template <class T>
  35. struct lazy_enable_if_c<false, T> {};
  36. template <class Cond, class T>
  37. struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
  38. template <bool B, class T = void>
  39. struct disable_if_c {
  40. typedef T type;
  41. };
  42. template <class T>
  43. struct disable_if_c<true, T> {};
  44. template <class Cond, class T = void>
  45. struct disable_if : public disable_if_c<Cond::value, T> {};
  46. template <bool B, class T>
  47. struct lazy_disable_if_c {
  48. typedef typename T::type type;
  49. };
  50. template <class T>
  51. struct lazy_disable_if_c<true, T> {};
  52. template <class Cond, class T>
  53. struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
  54. } // namespace boost
  55. #else
  56. namespace boost {
  57. namespace detail { typedef void enable_if_default_T; }
  58. template <typename T>
  59. struct enable_if_does_not_work_on_this_compiler;
  60. template<typename T, typename R=void>
  61. struct enable_if_has_type : enable_if_does_not_work_on_this_compiler<T>
  62. { };
  63. template <bool B, class T = detail::enable_if_default_T>
  64. struct enable_if_c : enable_if_does_not_work_on_this_compiler<T>
  65. { };
  66. template <bool B, class T = detail::enable_if_default_T>
  67. struct disable_if_c : enable_if_does_not_work_on_this_compiler<T>
  68. { };
  69. template <bool B, class T = detail::enable_if_default_T>
  70. struct lazy_enable_if_c : enable_if_does_not_work_on_this_compiler<T>
  71. { };
  72. template <bool B, class T = detail::enable_if_default_T>
  73. struct lazy_disable_if_c : enable_if_does_not_work_on_this_compiler<T>
  74. { };
  75. template <class Cond, class T = detail::enable_if_default_T>
  76. struct enable_if : enable_if_does_not_work_on_this_compiler<T>
  77. { };
  78. template <class Cond, class T = detail::enable_if_default_T>
  79. struct disable_if : enable_if_does_not_work_on_this_compiler<T>
  80. { };
  81. template <class Cond, class T = detail::enable_if_default_T>
  82. struct lazy_enable_if : enable_if_does_not_work_on_this_compiler<T>
  83. { };
  84. template <class Cond, class T = detail::enable_if_default_T>
  85. struct lazy_disable_if : enable_if_does_not_work_on_this_compiler<T>
  86. { };
  87. } // namespace boost
  88. #endif // BOOST_NO_SFINAE
  89. #endif