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