2 #ifndef BOOST_MPL_IF_HPP_INCLUDED
3 #define BOOST_MPL_IF_HPP_INCLUDED
5 // + file: boost/mpl/if.hpp
6 // + last modified: 17/sep/03
8 // Copyright (c) 2000-03 Boost.org
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.
18 // See http://www.boost.org/libs/mpl for documentation.
20 #include "boost/mpl/void.hpp"
21 #include "boost/mpl/aux_/value_wknd.hpp"
22 #include "boost/mpl/aux_/static_cast.hpp"
23 #include "boost/mpl/aux_/void_spec.hpp"
24 #include "boost/mpl/aux_/lambda_support.hpp"
25 #include "boost/mpl/aux_/config/workaround.hpp"
26 #include "boost/config.hpp"
28 #if !defined(BOOST_MPL_NO_FULL_LAMBDA_SUPPORT)
29 # include "boost/mpl/arg_fwd.hpp"
35 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
37 BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
53 struct if_c<false,T1,T2>
59 typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C)
60 , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
61 , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
66 // agurt, 02/jan/03: two-step 'type' definition for the sake of aCC
68 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561))
69 BOOST_MPL_AUX_VALUE_WKND(C)::value
71 BOOST_MPL_AUX_STATIC_CAST(bool, BOOST_MPL_AUX_VALUE_WKND(C)::value)
78 typedef typename almost_type_::type type;
80 BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
85 // no partial class template specialization
92 template< typename T1, typename T2 > struct result_
101 template< typename T1, typename T2 > struct result_
116 typedef typename aux::if_impl< C_ >
117 ::template result_<T1,T2>::type type;
120 // (almost) copy & paste in order to save one more
121 // recursively nested template instantiation to user
123 typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C_)
124 , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
125 , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
129 enum { msvc70_wknd_ = C_::value };
131 typedef typename aux::if_impl< BOOST_MPL_AUX_STATIC_CAST(bool, msvc70_wknd_) >
132 ::template result_<T1,T2>::type type;
134 BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C_,T1,T2))
137 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
139 BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
141 BOOST_MPL_AUX_ALGORITHM_VOID_SPEC(3, if_)
144 #if !defined(BOOST_MPL_NO_FULL_LAMBDA_SUPPORT)
146 // Aleksey, check it out: lazy if_ evaluation in lambdas!
147 // I think this doesn't handle the case of
149 // _1<foo<_2>, bar<_2>, baz<_2> >
151 // (or however it is that you express that... when the ordinary bind3
152 // computes the function based on the actual arguments). That leads me
153 // to think that some kind of true currying might be a better
157 // boost::mpl::bind3<
158 // boost::mpl::quote3<boost::mpl::if_>
159 // , boost::mpl::bind1<boost::mpl::quote1<boost::is_reference>, boost::mpl::arg<1> >
160 // , boost::mpl::arg<1>
161 // , boost::mpl::bind1<boost::mpl::quote1<add_ptr>, boost::mpl::arg<1> >
167 // boost::mpl::quote3<boost::mpl::if_>
169 // , boost::mpl::bind1<boost::mpl::quote1<boost::is_reference>,
170 // boost::mpl::arg<1> >
172 // boost::mpl::arg<1>
174 // boost::mpl::bind1<boost::mpl::quote1<add_ptr>, boost::mpl::arg<1> >
177 // so that after the 2nd bind we have a different function depending
178 // on the result of is_reference.
180 template <class T1, class T2, class T3, class T4> struct bind3;
181 template <template <class T1, class T2, class T3> class F, class tag> struct quote3;
187 , BOOST_MPL_PP_PARAMS(BOOST_MPL_METAFUNCTION_MAX_ARITY, typename U)
188 > struct resolve_bind_arg;
194 struct replace_unnamed_arg;
198 typename T1, typename T2, typename T3
200 struct bind3<quote3<if_, void_>, T1, T2, T3>
203 typename U1 = void_, typename U2 = void_, typename U3 = void_
204 , typename U4 = void_, typename U5 = void_
209 typedef quote3<if_, void_> a0;
210 typedef mpl::arg< 1> n1;
212 typedef aux::replace_unnamed_arg< T1,n1 > r1;
213 typedef typename r1::type a1;
214 typedef typename r1::next_arg n2;
215 typedef typename aux::resolve_bind_arg< a1,U1,U2,U3,U4,U5 >::type t1;
217 typedef aux::replace_unnamed_arg< T2,n2 > r2;
218 typedef typename r2::type a2;
219 typedef typename r2::next_arg n3;
220 typedef typename aux::resolve_bind_arg< a2,U1,U2,U3,U4,U5 > f2;
222 typedef aux::replace_unnamed_arg< T3,n3 > r3;
223 typedef typename r3::type a3;
224 typedef typename r3::next_arg n4;
225 typedef typename aux::resolve_bind_arg< a3,U1,U2,U3,U4,U5 > f3;
227 typedef typename if_<t1,f2,f3>::type f_;
229 typedef typename f_::type type;
237 #endif // BOOST_MPL_IF_HPP_INCLUDED