|
Boost Users : |
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2003-02-25 07:07:22
Markus Werle wrote:
> >> Q3: (OT) Is there a mpl-equivalent to run-time case?
> >
> > :-)
> >
> > Aleksey and I have been discussing some shorthands for
> >
> > if (c1) then t1
> > else if (c2) then t2
> > else if (c3) then t3
> > ...
> > else if (c4) then t4
> >
> > but that's not quite the same as a case statement.
>
> A std::map equivalent would help here a lot.
> It should be possible to search within a typelist of
> std::pair<condition, type> ...
> Unfortunately I am still stumbling through the mpl
> source [getting mad about all those
> WORKAROUND_FOR(STUPID_COMPILER_VENDOR)]
>
> Could You please give me an idea how to
> search within such a typelist?
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?
Aleskey
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