Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-05-19 07:11:43


Aleksey Gurtovoy <agurtovoy_at_[hidden]> writes:

> The problem here is that the result of 'boost::bind( &add_two, _1 )'
> takes its argument by reference, while transform_iterator's
> 'dereference' implementation is:
>
> typename super_t::reference dereference() const
> { return m_f(*this->base()); }
> ^^^^^^^^^^^^^
>
> In our case, '*this->base()' produces a temporary 'int' which cannot
> be directly passed to 'm_f'.
>
> Effectively, the issue prevents you from layering any iterator
> adaptors built with 'boost::bind' on top of 'transform_iterator',

Only if the underlying iterator is an input iterator whose dereference
returns by value, right?

> which, needless to say, is BAD.

Regrettable, I agree.

> My sugesstion would be to replace the above with
>
> typename super_t::reference dereference() const
> {
> typename iterator_reference<Iterator>::type x( *this->base() );
> return m_f( x );
> }

If it passes all tests I have no objections.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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