Boost logo

Boost :

Subject: [boost] howto: boost.lambda + stl on VS 2010 (SP1) ?
From: Raffi Enficiaud (raffi.enficiaud_at_[hidden])
Date: 2011-05-04 19:37:15


Hi all,

Sorry for bothering with this. I recently encountered some problems in using
boost.lambda with Visual 2010 Express, and need some clues for solving the
issue (there are many ways around of course).
I simply want to accumulate the values of a std::map, and I thought using
lambda to access the second member of the map iterator was appropriate. Here
is the piece of code:

typedef std::map<T1, unsigned short> m_t;
m_t m ; // fill m
double acc(0);
std::for_each(m.begin(), m.end(), var(acc) += & _1->*&
m_t::value_type::second);

The last line does not compile on Visual (it does on GCC), I have to add a
typedef:

typedef typename m_t::value_type aa;
std::for_each(m.begin(), m.end(), var(acc) += & _1->*& aa::second);

Which one is "more correct" ?

To this point, I thought that using accumulate would be cleaner:
std::accumulate(m.begin(), m.end(), double(0), & _1->*&aa::second);

But I have several compilation errors, and on the top of it:

1>(..)/boost-1_46_1\boost/lambda/detail/member_ptr.hpp(512): error C2296:
'->*' : illegal, left operand has type 'const rt0 '
1> boost/lambda/detail/member_ptr.hpp(622) : see reference to function
template instantiation 'RET
boost::lambda::detail::member_pointer_action_helper<true,false>::apply<RET,A
,B>(A &,B &)' being compiled
1> with
1> [
1> RET=unsigned short &,
1> A=rt0,
1> B=rt1
1> ]

I do not really understand what rt0/rt1 are. The former should be the
iterator::value_type and the latter the pointer to member.
Most of all, the call with accumulate looks very similar to the for_each one
to me.

So, is the problem between the keyboard and the chair ?

Best,
Raffi


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk