
Joaquín Mª López Muñoz wrote:
Scott Meyers ha escrito:
[...]
What I really want is something more like do_until<Sequence>(unaryFunctionObject) that will loop over all the entries in Sequence until the unaryFunctionObject returns true. Is there something like this in the MPL, must I roll my own, or am I approaching this the wrong way entirely?
AFAIK you must roll your own. Please find attached a possible implementation using mpl::fold.
This is unnecessarily inefficient. It's pretty easy to just use iterators, something like: template <class First, class Last, class F> bool do_until_impl(First, Last, F f) { boost::value_initialized<typename mpl::deref<First>::type> x; if (f(boost::get(x))) return true; return do_until_impl( typename mpl::next<First>::type(), Last(), f); } template <class Last, class F> bool do_until_impl(Last, Last, F) { return false; } template <class Seq, class F> bool do_until(F f) { return do_until_impl( typename mpl::begin<Seq>::type() , typename mpl::end<Seq>::type() , f ); } -- Daniel Wallin Boost Consulting www.boost-consulting.com