Boost logo

Boost :

Subject: [boost] Proposed interface change to boost::algorithm::copy_while
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2013-02-20 13:55:16


In 1.50, I introduced:

        template<typename InputIterator, typename OutputIterator, typename Predicate>
        OutputIterator
        copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p );

(and copy_until), which do pretty much what you would expect: copy items from the input to the output as long as the predicate holds.

Sean Parent has convinced me that this is wrong; that I have to return the modified input iterator as well.
When I wrote these, I was thinking (if I actually was thinking) of actual input iterators, and since they're all the same, so the caller can pick up on the input sequence after the call returns. However, if you're processing (say) a list, it would be kind of useful to know how far in the list the call advanced.

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 were not using these calls because they didn't return the input iterator, now you can.

Questions? Comments? (Except for the "How could you miss that when you wrote those routines?" - I've already asked myself that)
Improvements?

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki


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