if.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef BOOST_MPL_IF_HPP_INCLUDED
  2. #define BOOST_MPL_IF_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/aux_/value_wknd.hpp>
  14. #include <boost/mpl/aux_/static_cast.hpp>
  15. #include <boost/mpl/aux_/na_spec.hpp>
  16. #include <boost/mpl/aux_/lambda_support.hpp>
  17. #include <boost/mpl/aux_/config/integral.hpp>
  18. #include <boost/mpl/aux_/config/ctps.hpp>
  19. #include <boost/mpl/aux_/config/workaround.hpp>
  20. namespace boost { namespace mpl {
  21. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  22. template<
  23. bool C
  24. , typename T1
  25. , typename T2
  26. >
  27. struct if_c
  28. {
  29. typedef T1 type;
  30. };
  31. template<
  32. typename T1
  33. , typename T2
  34. >
  35. struct if_c<false,T1,T2>
  36. {
  37. typedef T2 type;
  38. };
  39. // agurt, 05/sep/04: nondescriptive parameter names for the sake of DigitalMars
  40. // (and possibly MWCW < 8.0); see https://lists.boost.org/Archives/boost/2004/09/71383.php
  41. template<
  42. typename BOOST_MPL_AUX_NA_PARAM(T1)
  43. , typename BOOST_MPL_AUX_NA_PARAM(T2)
  44. , typename BOOST_MPL_AUX_NA_PARAM(T3)
  45. >
  46. struct if_
  47. {
  48. private:
  49. // agurt, 02/jan/03: two-step 'type' definition for the sake of aCC
  50. typedef if_c<
  51. #if defined(BOOST_MPL_CFG_BCC_INTEGRAL_CONSTANTS)
  52. BOOST_MPL_AUX_VALUE_WKND(T1)::value
  53. #else
  54. BOOST_MPL_AUX_STATIC_CAST(bool, BOOST_MPL_AUX_VALUE_WKND(T1)::value)
  55. #endif
  56. , T2
  57. , T3
  58. > almost_type_;
  59. public:
  60. typedef typename almost_type_::type type;
  61. BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(T1,T2,T3))
  62. };
  63. #else
  64. // no partial class template specialization
  65. namespace aux {
  66. template< bool C >
  67. struct if_impl
  68. {
  69. template< typename T1, typename T2 > struct result_
  70. {
  71. typedef T1 type;
  72. };
  73. };
  74. template<>
  75. struct if_impl<false>
  76. {
  77. template< typename T1, typename T2 > struct result_
  78. {
  79. typedef T2 type;
  80. };
  81. };
  82. } // namespace aux
  83. template<
  84. bool C_
  85. , typename T1
  86. , typename T2
  87. >
  88. struct if_c
  89. {
  90. typedef typename aux::if_impl< C_ >
  91. ::template result_<T1,T2>::type type;
  92. };
  93. // (almost) copy & paste in order to save one more
  94. // recursively nested template instantiation to user
  95. template<
  96. typename BOOST_MPL_AUX_NA_PARAM(C_)
  97. , typename BOOST_MPL_AUX_NA_PARAM(T1)
  98. , typename BOOST_MPL_AUX_NA_PARAM(T2)
  99. >
  100. struct if_
  101. {
  102. enum { msvc_wknd_ = BOOST_MPL_AUX_MSVC_VALUE_WKND(C_)::value };
  103. typedef typename aux::if_impl< BOOST_MPL_AUX_STATIC_CAST(bool, msvc_wknd_) >
  104. ::template result_<T1,T2>::type type;
  105. BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C_,T1,T2))
  106. };
  107. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  108. BOOST_MPL_AUX_NA_SPEC(3, if_)
  109. }}
  110. #endif // BOOST_MPL_IF_HPP_INCLUDED