mpl::find_if / placeholder question

Hi, 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; BOOST_MPL_ASSERT_RELATION( iter::pos::value, == , 1); Using BOOST version 1.38, GCC4.3. Thank You -- View this message in context: http://www.nabble.com/mpl%3A%3Afind_if---placeholder-question-tp23463044p234... Sent from the Boost - Users mailing list archive at Nabble.com.

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
participants (2)
-
Steven Watanabe
-
vasyl_y