Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-27 18:54:23


Markus Werle <yg-boost-users_at_[hidden]> writes:

> Aleksey Gurtovoy wrote:
>
>
>> With the current CVS, you don't have to do it by yourself:
>>
>> #include "boost/mpl/vector.hpp"
>> #include "boost/mpl/switch.hpp"
>> #include "boost/mpl/project1st.hpp"
>> #include "boost/mpl/pair.hpp"
>> #include "boost/mpl/always.hpp"
>> #include "boost/mpl/bool_c.hpp"
>> #include "boost/mpl/assert_is_same.hpp"
>>
>> #include "boost/type_traits/remove_reference.hpp"
>> #include "boost/type_traits/add_const.hpp"
>> #include "boost/type_traits/is_pointer.hpp"
>> #include "boost/type_traits/is_reference.hpp"
>>
>> using namespace boost::mpl;
>>
>> typedef vector<
>> pair< boost::is_pointer<_1>, _1 >
>> , pair< boost::is_reference<_1>, boost::remove_reference<_1> >
>> , pair< always<true_c>, boost::add_const<_1> >
>> > switch_body;
>>
>> typedef switch_< switch_body, char& >::type t1;
>> typedef switch_< switch_body, int* >::type t2;
>> typedef switch_< switch_body, int >::type t3;
>>
>> BOOST_MPL_ASSERT_IS_SAME(t1, char);
>> BOOST_MPL_ASSERT_IS_SAME(t2, int*);
>> BOOST_MPL_ASSERT_IS_SAME(t3, int const);
>>
>> Does it cover your needs?
>
> It covers my needs and it makes me feel like a stupid
> KnowNothing (after 5 years in expression template
> metaprogramming)
>
>
> What are the requirements for the struct
> some_condition<_1> to be used in such a switch body?

It should be a unary lambda expression or metafunction class returning
an integral constant wrapper. It is evaluated on the 2nd switch
argument to determine whether that case is selected.

The definition of a lambda expression is:

   A lambda expression is a placeholder or a template with at least
   one argument that is a lambda expression.

For now, "always<X>" is also a lambda expression.

A metafunction class is a class with a nested metafunction named
"apply"

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net