Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2005-05-19 23:31:09


David Abrahams writes:
> 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?

Well, only if you talk in old iterator categories ;).

>
>> 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.

OK, thanks!

-- 
Aleksey Gurtovoy
MetaCommunications Engineering

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