Boost logo

Boost Users :

Subject: Re: [Boost-users] [mpl] Using max_element inside a fold while constructing a vector
From: Brendon Costa (brendon.j.costa_at_[hidden])
Date: 2013-05-31 21:35:53


>
> try push_back<_1, deref<max_element<_1> > >.
> i.e. don't use ::type in an MPL Lambda expression.
>
>
>
That doesn't work either. Below is a full code example as I think it should
be from your feedback (I have tried in GCC and MSVC2010):

#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/max_element.hpp>
#include <boost/mpl/deref.hpp>
#include <iostream>
#include <typeinfo>

using namespace boost::mpl;
using namespace boost::mpl::placeholders;

typedef vector<int_<0>, int_<3>, int_<2> > v1;

// I want to use max_element on a vector I am in the process of
constructing using a fold
typedef fold<v1, vector<int_<0> >, push_back<_1, deref<max_element<_1> > >
>::type v2;

struct print_value
{
template <typename data_tpt>
void operator()(data_tpt p)
{
//Uncommenting this is what I would like but fails to compile
//std::cerr << "value: " << data_tpt::value << std::endl;
std::cerr << "value: " << typeid(p).name() << std::endl;
}
};

int main()
{
for_each<v2,_>(print_value());
return 0;
}

This produces a compile error in MSVC 2010 and compiles on GCC but produces
bad results:

value: N4mpl_4int_ILi0EEE
value:
N5boost3mpl5derefINS0_11max_elementIN4mpl_3argILi1EEENS0_4lessINS4_ILin1EEES7_EEEEEE
value:
N5boost3mpl5derefINS0_11max_elementIN4mpl_3argILi1EEENS0_4lessINS4_ILin1EEES7_EEEEEE
value:
N5boost3mpl5derefINS0_11max_elementIN4mpl_3argILi1EEENS0_4lessINS4_ILin1EEES7_EEEEEE

I expect all to be similar to: N4mpl_4int_ILi0EEE



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