[MPL] - for_each operators with decision branching

I have a project in which I use these things I call "records" to attach
data to edges and vertexes in a boost::graph. They are visitable
(acyclic visitor described by Alexandrescu) and I have metafunctions
that will take their most derived type and give me a list of "fields"
that they contain. I can then write generic processors to do things
like build editors for them or perform operations that can effect any
field of a particular type or concept. Thus I often find myself using
mpl::for_each and writing things like this:
struct operator
{
template < typename MetaField >
void operator()(MetaField const&, boost::enable_if< some_test >::type
* = 0);
template < typename MetaField >
void operator()(MetaField const&, boost::disable_if

Zitat von Noah Roberts
struct operator { template < typename MetaField > void operator()(MetaField const&, boost::enable_if< some_test >::type * = 0); template < typename MetaField > void operator()(MetaField const&, boost::disable_if
::type * = 0); };
the point of code like this usually is to only instantiate the branch that is chosen, otherwise you could just use if(some_test::value)...else... that means that the two branches must be in different functions, so I don't see a way to make this any easier, or how a library like MPL could. you can however avoid the use of enable_if, if you prefer: void operator()(T t){ this->operator()(t,typename some_test<...>::type()); } void opeartor()(T t,mpl::true_ test_is_true){ ... } void opeartor()(T t,mpl::false_){ ... } this also makes writing 3 or more branches (if...elseif...else) easier because you can use more than one condition parameter for overloading.
participants (2)
-
Noah Roberts
-
strasser@uni-bremen.de