if_else.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef IF_ELSE_DWA2002322_HPP
  6. # define IF_ELSE_DWA2002322_HPP
  7. # include <boost/config.hpp>
  8. namespace boost { namespace python { namespace detail {
  9. template <class T> struct elif_selected;
  10. template <class T>
  11. struct if_selected
  12. {
  13. template <bool b>
  14. struct elif : elif_selected<T>
  15. {
  16. };
  17. template <class U>
  18. struct else_
  19. {
  20. typedef T type;
  21. };
  22. };
  23. # if defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
  24. namespace msvc70_aux {
  25. template< bool > struct inherit_from
  26. {
  27. template< typename T > struct result
  28. {
  29. typedef T type;
  30. };
  31. };
  32. template<> struct inherit_from<true>
  33. {
  34. template< typename T > struct result
  35. {
  36. struct type {};
  37. };
  38. };
  39. template< typename T >
  40. struct never_true
  41. {
  42. BOOST_STATIC_CONSTANT(bool, value = false);
  43. };
  44. } // namespace msvc70_aux
  45. #endif // # if defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
  46. template <class T>
  47. struct elif_selected
  48. {
  49. # if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407)
  50. template <class U> class then;
  51. # elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
  52. template <class U>
  53. struct then : msvc70_aux::inherit_from< msvc70_aux::never_true<U>::value >
  54. ::template result< if_selected<T> >::type
  55. {
  56. };
  57. # else
  58. template <class U>
  59. struct then : if_selected<T>
  60. {
  61. };
  62. # endif
  63. };
  64. # if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407)
  65. template <class T>
  66. template <class U>
  67. class elif_selected<T>::then : public if_selected<T>
  68. {
  69. };
  70. # endif
  71. template <bool b> struct if_
  72. {
  73. template <class T>
  74. struct then : if_selected<T>
  75. {
  76. };
  77. };
  78. struct if_unselected
  79. {
  80. template <bool b> struct elif : if_<b>
  81. {
  82. };
  83. template <class U>
  84. struct else_
  85. {
  86. typedef U type;
  87. };
  88. };
  89. template <>
  90. struct if_<false>
  91. {
  92. template <class T>
  93. struct then : if_unselected
  94. {
  95. };
  96. };
  97. }}} // namespace boost::python::detail
  98. #endif // IF_ELSE_DWA2002322_HPP