Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-04-23 10:37:43

Vladimir Prus <ghost_at_[hidden]> writes:

> I'm again trying to use FP in C++, and having problems. What I wanted to do
> was:
> for_each(predecesor(v, g), /* BLL expression */ );
> where predecessor(..) returns a pair of 'transform_iterator' instances. The
> simplest example which illustrates the problem is:
> struct functor {
> typedef int result_type;
> int operator()(int i) const { return i+1; };
> };
> transform_iterator<functor, vector<int>::iterator> it(v.begin());
> (cout << _1)(*it);
> This does not compile, because operator* of transform_iterator return rvalue
> which can't be bound to non-const reference that operator() of the lambda
> expression accepts.
> Of all workarounds suggsted on BLL docs, only break_const is applicable to my
> case (I want to pass non-const references to the lambda, so const_parameters
> won't do), and break_const is scary.
> It looks like a serious problem with using FP, so I wonder what can be done.
> Maybe, transform_iterator should have yet another template parameter telling
> if it should store a value internally, and return reference (i.e. lvalue) in
> that case? It need not be enabled by default, but functions like my
> 'predecessor' above would make use of that extra template parameter.

I brought up this issue a few weeks ago. I was thinking we should be
able to write

or maybe


to pass rvalues.

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at