]> git.lyx.org Git - lyx.git/blob - boost/boost/mpl/if.hpp
Boost version 1.30.0
[lyx.git] / boost / boost / mpl / if.hpp
1
2 #ifndef BOOST_MPL_IF_HPP_INCLUDED
3 #define BOOST_MPL_IF_HPP_INCLUDED
4
5 // + file: boost/mpl/if.hpp
6 // + last modified: 10/mar/03
7
8 // Copyright (c) 2000-03 Boost.org
9 //
10 // Permission to use, copy, modify, distribute and sell this software
11 // and its documentation for any purpose is hereby granted without fee, 
12 // provided that the above copyright notice appears in all copies and 
13 // that both the copyright notice and this permission notice appear in 
14 // supporting documentation. No representations are made about the 
15 // suitability of this software for any purpose. It is provided "as is" 
16 // without express or implied warranty.
17 //
18 // See http://www.boost.org/libs/mpl for documentation.
19
20 #include "boost/mpl/aux_/value_wknd.hpp"
21 #include "boost/mpl/aux_/ice_cast.hpp"
22 #include "boost/mpl/aux_/void_spec.hpp"
23 #include "boost/mpl/aux_/lambda_support.hpp"
24 #include "boost/mpl/aux_/config/workaround.hpp"
25 #include "boost/config.hpp"
26
27 namespace boost {
28 namespace mpl {
29
30 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
31
32 template<
33       bool C
34     , typename T1
35     , typename T2
36     >
37 struct if_c
38 {
39     typedef T1 type;
40 };
41
42 template<
43       typename T1
44     , typename T2
45     >
46 struct if_c<false,T1,T2>
47 {
48     typedef T2 type;
49 };
50
51 template<
52       typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C)
53     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
54     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
55     >
56 struct if_
57 {
58  private:
59     // agurt, 02/jan/03: two-step 'type' definition for the sake of aCC 
60     typedef if_c<
61 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561))
62           BOOST_MPL_AUX_VALUE_WKND(C)::value
63 #else
64           BOOST_MPL_AUX_ICE_CAST(bool, BOOST_MPL_AUX_VALUE_WKND(C)::value)
65 #endif
66         , T1
67         , T2
68         > almost_type_;
69  
70  public:
71     typedef typename almost_type_::type type;
72     
73     BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
74 };
75
76 #elif defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
77
78 // MSVC6.5-specific version
79
80 template<
81       bool C_
82     , typename T1
83     , typename T2
84     >
85 struct if_c
86 {
87  private:
88     template<bool> struct answer        { typedef T1 type; };
89     template<>     struct answer<false> { typedef T2 type; };
90  
91  public:
92     typedef typename answer< C_ >::type type;
93 };
94
95 // (almost) copy & paste in order to save one more 
96 // recursively nested template instantiation to user
97 template<
98       typename C_
99     , typename T1
100     , typename T2
101     >
102 struct if_
103 {
104  private:
105     template<bool> struct answer        { typedef T1 type; };
106     template<>     struct answer<false> { typedef T2 type; };
107
108     // agurt, 17/sep/02: in some situations MSVC 7.0 doesn't 
109     // handle 'answer<C::value>' expression very well
110     enum { c_ = C_::value };
111
112  public:
113     typedef typename answer< BOOST_MPL_AUX_ICE_CAST(bool, c_) >::type type;
114
115     BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C_,T1,T2))
116 };
117
118 #else
119
120 // no partial class template specialization
121
122 namespace aux {
123
124 template< bool C >
125 struct if_impl
126 {
127     template< typename T1, typename T2 > struct result_
128     {
129         typedef T1 type;
130     };
131 };
132
133 template<>
134 struct if_impl<false>
135 {
136     template< typename T1, typename T2 > struct result_
137     { 
138         typedef T2 type;
139     };
140 };
141
142 } // namespace aux
143
144 template<
145       bool C
146     , typename T1
147     , typename T2
148     >
149 struct if_c
150 {
151     typedef typename aux::if_impl< C >
152         ::template result_<T1,T2>::type type;
153 };
154
155 // (almost) copy & paste in order to save one more 
156 // recursively nested template instantiation to user
157 template<
158       typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C)
159     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
160     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
161     >
162 struct if_
163 {
164     typedef typename aux::if_impl< BOOST_MPL_AUX_ICE_CAST(bool, C::value) >
165         ::template result_<T1,T2>::type type;
166
167     BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
168 };
169
170 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
171
172 BOOST_MPL_AUX_VOID_SPEC(3, if_)
173
174 } // namespace mpl
175 } // namespace boost
176
177 #endif // BOOST_MPL_IF_HPP_INCLUDED