Boost logo

Boost Users :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2005-06-14 20:36:28


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<Seq,F>
            , is_not_void_<_1>
>::type iter_;

        typedef typename eval_if<
              is_same< typename iter_::base, typename end<Seq>::type >
            , void_
            , deref<iter_>
>::type type;
    };

>
> 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 ;).

-- 
Aleksey Gurtovoy
MetaCommunications Engineering

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net