Boost logo

Boost :

Subject: Re: [boost] Proposed interface change to boost::algorithm::copy_while
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2013-02-20 15:26:12


On 20.02.2013, at 19:55, Marshall Clow wrote:

> I'm proposing to change the interface to:
>
> template<typename InputIterator, typename OutputIterator, typename Predicate>
> std::pair<InputIterator, OutputIterator>
> copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p );
>
> i.e, changing the return type to return both iterators.
>
> What this means:
> * If you're not calling copy_while (or copy_until), then this change won't affect you.
> * If you're not using the return value, then this change won't affect you.
> * If you are using the return value, then you will have to change your code thus:
> Old foo = copy_while ( first, last, out, p );
> New: foo = copy_while ( first, last, out, p ).second;

If you want to ease transition, I once wrote a biased_pair type, which is basically a pair with an implicit conversion to one of its member types.

template <typename T1, typename T2>
struct right_biased_pair { // consider deriving from std::pair instead of aping it
  T1 first;
  T2 second;

  // constructors and stuff

  operator std::pair<T1, T2>() { return std::pair<T1, T2>(first, second); }

  // the bias
  operator T2() const { return second; }
};

Then you can make copy_while return a right_biased_pair<InputIterator, OutputIterator> and code of the form
out = copy_while(first, last, out, p);
will keep working.

No idea if that's worth it to you, just saying that the option is there.

Sebastian


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