1 //-----------------------------------------------------------------------------
2 // boost/mpl/if.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
6 // Copyright (c) 2000-02 Boost.org
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.
16 #ifndef BOOST_MPL_IF_HPP_INCLUDED
17 #define BOOST_MPL_IF_HPP_INCLUDED
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"
29 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
45 struct if_c<false,T1,T2>
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)
58 // agurt, 02/jan/03: two-step 'type' definition for the sake of aCC
60 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561))
61 BOOST_MPL_AUX_VALUE_WKND(C)::value
63 BOOST_MPL_AUX_ICE_CAST(bool, BOOST_MPL_AUX_VALUE_WKND(C)::value)
70 typedef typename almost_type_::type type;
72 BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
75 #elif defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
77 // MSVC6.5-specific version
87 template<bool> struct answer { typedef T1 type; };
88 template<> struct answer<false> { typedef T2 type; };
91 typedef typename answer< C_ >::type type;
94 // (almost) copy & paste in order to save one more
95 // recursively nested template instantiation to user
104 template<bool> struct answer { typedef T1 type; };
105 template<> struct answer<false> { typedef T2 type; };
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 };
112 typedef typename answer< BOOST_MPL_AUX_ICE_CAST(bool, c_) >::type type;
114 BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C_,T1,T2))
119 // no partial class template specialization
126 template< typename T1, typename T2 > struct result_
133 struct if_impl<false>
135 template< typename T1, typename T2 > struct result_
150 typedef typename aux::if_impl< C >
151 ::template result_<T1,T2>::type type;
154 // (almost) copy & paste in order to save one more
155 // recursively nested template instantiation to user
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)
163 typedef typename aux::if_impl< BOOST_MPL_AUX_ICE_CAST(bool, C::value) >
164 ::template result_<T1,T2>::type type;
166 BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
169 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
171 BOOST_MPL_AUX_VOID_SPEC(3, if_)
176 #endif // BOOST_MPL_IF_HPP_INCLUDED