Boost logo

Boost :

Subject: Re: [boost] Proposed interface change to boost::algorithm::copy_while
From: Eric Niebler (eniebler_at_[hidden])
Date: 2013-02-26 16:06:55

On 13-02-26 01:00 PM, Marshall Clow wrote:
> On Feb 26, 2013, at 12:50 PM, Jonathan Wakely <jwakely.boost_at_[hidden]> wrote:
>> On 26 February 2013 20:36, Marshall Clow wrote:
>>> I just realized another reason not to like this.
>>> If your prototype looks like this:
>>> template<typename InputIterator, typename OutputIterator, typename Predicate>
>>> OutputIterator copy_while ( InputIterator &first, InputIterator last, OutputIterator result, Predicate );
>>> you can't call it like this:
>>> copy_while ( v.begin (), v.end (), out, pred );
>> But you could add the by-reference form as an overload, existing code
>> passing an rvalue gets the old behaviour and doesn't get the extra
>> information, which is OK because they never got it before now anyway.
> Yes, but existing callers who were passing an lvalue get a silent change in behavior; their variable changes out from under them.

There is no precedent in the standard library of passing an iterator by
reference to an algorithm and having the algorithm mutate it. In/out
parameters are not in keeping with the functional style of the STL. IMO,
this would be a very poor choice for the interface. Very error prone,
very surprising.

Eric Niebler

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