
Vyacheslav Kononenko
--- Aleksey Gurtovoy
wrote: Vyacheslav Kononenko writes:
I could not come with usable name for such thing but it could be usable anyway. So it is like find_if but applies a function to an sequence and return first non void type that function returned. So implementation would be trivial:
template< typename Sequence, typename Func > struct find_type : fold< Sequence, void_, if_< is_void_< _1 >, Func< _2 >, _1 > {};
Or, which is likely to be more efficient,
template< typename Seq, typename F > struct find_type { typedef typename find_if< transform_view
, is_not_void_<_1> >::type iter_; typedef typename eval_if< is_same< typename iter_::base, typename end<Seq>::type > , void_ , deref
>::type type; }; Correct my if I am wrong but your will invoke F on every element when mine will not.
transform_view is lazy, so F will only be invoked until it returns a non-void_ result.
If it can be implemented by current set of algorithms please point me out.
Doesn't your sketch above employ an algorithm from the current set ('fold')? In any case, at the moment this feels too specialized to me to be considered for inclusion in the library. At the very least, it needs a name ;).
There is another topic about mpl for_each and I think my algo would be usable there. But for the name it is an author work to make names isn't it?
You appear to be the author of this algorithm ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com