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