c++ - Is there a way to break out of boost::mpl for_each? -


simple question really, let me give background:

i have mpl::vector of types each type has id, @ run time use mpl::for_each iterate through vector , find matching type given id. once found, there no point in continuing loop, - question is, there way break out of (without throwing exception)?

nope, there no way 'break' mpl::for_each. being said, might have misunderstood problem, seems me need mpl::find_if more mpl::for_each :

#include <boost/mpl/find_if.hpp> #include <boost/mpl/vector.hpp>  template<int n> struct foo { enum { id = n }; };  template<int n> struct has_nested_id {     template<class t>     struct apply {         static const bool value = (n == t::id);     }; };  int main() {     typedef boost::mpl::find_if         <             boost::mpl::vector<foo<1>, foo<2>, foo<3> >,             has_nested_id<3>::apply<boost::mpl::_1>         >::type iterator_type;      typedef boost::mpl::deref<iterator_type>::type type; // result foo<3> } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -