Boost logo

Boost Users :

Subject: Re: [Boost-users] mpl::find_if / placeholder question
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-05-09 18:10:05


AMDG

vasyl_y wrote:
> I started learn mpl and here we go...
> I have an mpl::vector of compund types and i want to find an element in
> vector based on
> property of compound type and cannot find the way to do it, any suggestions?
>
> Here is an example how i'm trying to do it:
>
> #include <boost/mpl/vector.hpp>
> #include <boost/mpl/find_if.hpp>
> #include <boost/type_traits.hpp>
>
> namespace mpl = boost::mpl;
>
> template<typename T, int id>
> struct Type2IdLink {
> typedef T value_type;
> typedef mpl::int_<id> type_id;
> };
>
> typedef Type2IdLink<char, 1> v1;
> typedef Type2IdLink<int, 2> v2;
> typedef Type2IdLink<unsigned, 3> v3;
>
> typedef mpl::vector<v1, v2, v3> types;
> // This work
> typedef mpl::find_if<types, boost::is_same<mpl::_1, v2> >::type iter;
> // This does not work:
> // value_type is not a member of mpl_::_1
> typedef mpl::find_if<types, boost::is_same<mpl::_1::value_type, v2> >::type
> iter;
>

You need to use a metafunction, since mpl::_1 has no member named
value_type.

template<class T>
struct value_type {
    typedef typename T::value_type type;
};

typedef mpl::find_if<types, boost::is_same<value_type<mpl::_1>, v2>
>::type iter;

In Christ,
Steven Watanabe


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