Boost logo

Boost Users :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2003-02-27 06:38:16


Markus Werle wrote:
> > 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);

[...]

> What are the requirements for the struct
> some_condition<_1> to be used in such a switch body?

'some_condition' should be a metafunction
(http://www.mywikinet.com/mpl/ref/Metafunction.html) "returning" a bool
Integral Constant (http://www.mywikinet.com/mpl/ref/Integral_Constant.html),
e.g.

using namespace boost::mpl;

template< typename T > struct silly
{
    typedef bool_<(sizeof(T) > 50)> type;
};

typedef vector<
      pair< silly<_1>, always<void> >
    , pair< always<true_>, _1 >
> switch_body;

typedef switch_< switch_body, char[51] >::type t1;

BOOST_MPL_ASSERT_IS_SAME(t1, void);

If you've got a conforming compiler, that's all.

HTH,
Aleksey


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