|
Boost Users : |
Subject: [Boost-users] [MPL] Fold a vector of pairs
From: Peter Nyssen (peter_at_[hidden])
Date: 2012-03-14 11:10:36
Nevermind.
Removing the typename before mpl::fold fixes it.
Kind regards,
Peter
//-------------------------------------
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/vector.hpp>
namespace mpl = boost::mpl;
struct tag1 {};
struct tag2 {};
template <typename T>
struct is_tag1 : boost::false_type {};
template <>
struct is_tag1<tag1> : boost::true_type {};
int main()
{
typedef mpl::vector<
mpl::pair<tag1, mpl::int_<1> >,
mpl::pair<tag2, mpl::int_<2> >,
mpl::pair<tag1, mpl::int_<3> >
> initial_vector;
typedef mpl::fold<
initial_vector,
mpl::pair<mpl::vector<>, mpl::vector<> >,
mpl::if_<
is_tag1<mpl::first<mpl::_2> >,
mpl::push_back<
mpl::first<mpl::_1>,
mpl::second<mpl::_2>
>,
mpl::push_back<
mpl::second<mpl::_1>,
mpl::second<mpl::_2>
>
>
>::type sorted_pair;
return 0;
}
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