
Zitat von Alexander Lamaison
I'm trying to recursively traverse an MPL vector_c but I'm not sure what the base-case type should be.
template<typename Sequence> // MAP is a vector_c struct dispatcher { template<typename T> static result dispatch(T* obj, unsigned int message_id, int arg) { typedef boost::mpl::front<Sequence>::type head; typedef boost::mpl::pop_front<Sequence>::type tail;
if (head::value == message_id) return obj->handle(messagehead::value, arg); else return dispatcher<tail>::dispatch(obj, message_id, arg); } };
template<> struct dispatcherboost::mpl::void_ // WHAT SHOULD THIS TYPE BE? { template<typename T> static result dispatch(T* obj, unsigned int message_id, int arg) { return obj->default_message_handler(message_id, arg); } };
I'm stuck on what to make the dispatcher base case which is reached when pop_front is called on a list with one item. At first I though the resulting type was void_ but apparently this doesn't match.
I'm new to MPL. Can someone explain what I'm doing wrong here or if there's an altogether better way?
if you encounter this type of thing regularily, you might want to have
a look at Boost.Fusion, which has runtime algorithms that can also be
used on Boost.MPL sequences.
however, using function templates is much simpler than the dispatch
class specialization you attempted above:
template