]> git.lyx.org Git - lyx.git/blob - boost/boost/mpl/if.hpp
complie fix
[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_/void_spec.hpp"
21 #include "boost/mpl/aux_/lambda_support.hpp"
22 #include "boost/config.hpp"
23
24 namespace boost {
25 namespace mpl {
26
27 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
28
29 template<
30       bool C
31     , typename T1
32     , typename T2
33     >
34 struct if_c
35 {
36     typedef T1 type;
37 };
38
39 template<
40       typename T1
41     , typename T2
42     >
43 struct if_c<false,T1,T2>
44 {
45     typedef T2 type;
46 };
47
48 template<
49       typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C)
50     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
51     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
52     >
53 struct if_
54 {
55     typedef typename if_c<
56           BOOST_MPL_AUX_VALUE_WKND(C)::value
57         , T1
58         , T2
59         >::type type;
60
61     BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
62 };
63
64 #elif defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
65
66 // MSVC6.5-specific version
67
68 template<
69       bool C
70     , typename T1
71     , typename T2
72     >
73 struct if_c
74 {
75  private:
76     template<bool> struct answer        { typedef T1 type; };
77     template<>     struct answer<false> { typedef T2 type; };
78  
79  public:
80     typedef typename answer< C >::type type;
81 };
82
83 // (almost) copy & paste in order to save one more 
84 // recursively nested template instantiation to user
85 template<
86       typename C
87     , typename T1
88     , typename T2
89     >
90 struct if_
91 {
92  private:
93     template<bool> struct answer        { typedef T1 type; };
94     template<>     struct answer<false> { typedef T2 type; };
95
96     // agurt, 17/sep/02: in some situations MSVC 7.0 doesn't 
97     // handle 'answer<C::value>' expression very well
98     enum { c_ = C::value };
99
100  public:
101     typedef typename answer<c_>::type type;
102 };
103
104 #else
105
106 // no partial class template specialization
107
108 namespace aux {
109
110 template< bool C >
111 struct if_impl
112 {
113     template< typename T1, typename T2 > struct result_
114     {
115         typedef T1 type;
116     };
117 };
118
119 template<>
120 struct if_impl<false>
121 {
122     template< typename T1, typename T2 > struct result_
123     { 
124         typedef T2 type;
125     };
126 };
127
128 } // namespace aux
129
130 template<
131       bool C
132     , typename T1
133     , typename T2
134     >
135 struct if_c
136 {
137     typedef typename aux::if_impl< C >
138         ::template result_<T1,T2>::type type;
139 };
140
141 // (almost) copy & paste in order to save one more 
142 // recursively nested template instantiation to user
143 template<
144       typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C)
145     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
146     , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
147     >
148 struct if_
149 {
150     typedef typename aux::if_impl< C::value >
151         ::template result_<T1,T2>::type type;
152
153     BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
154 };
155
156 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
157
158 BOOST_MPL_AUX_VOID_SPEC(3, if_)
159
160 } // namespace mpl
161 } // namespace boost
162
163 #endif // BOOST_MPL_IF_HPP_INCLUDED