This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

865. More algorithms that throw away information

Section: 27.7.6 [alg.fill], 27.7.7 [alg.generate] Status: C++11 Submitter: Daniel Krügler Opened: 2008-07-13 Last modified: 2016-01-28

Priority: Not Prioritized

View all issues with C++11 status.

Discussion:

In regard to library defect 488 I found some more algorithms which unnecessarily throw away information. These are typically algorithms, which sequentially write into an OutputIterator, but do not return the final value of this output iterator. These cases are:

  1. template<class OutputIterator, class Size, class T>
    void fill_n(OutputIterator first, Size n, const T& value);
  2. template<class OutputIterator, class Size, class Generator>
    void generate_n(OutputIterator first, Size n, Generator gen);

In both cases the minimum requirements on the iterator are OutputIterator, which means according to the requirements of 25.3.5.4 [output.iterators] p. 2 that only single-pass iterations are guaranteed. So, if users of fill_n and generate_n have only an OutputIterator available, they have no chance to continue pushing further values into it, which seems to be a severe limitation to me.

[ Post Summit Daniel "conceptualized" the wording. ]

[ Batavia (2009-05): ]

Alisdair likes the idea, but has concerns about the specific wording about the returns clauses.

Alan notes this is a feature request.

Bill notes we have made similar changes to other algorithms.

Move to Open.

[ 2009-07 Frankfurt ]

We have a consensus for moving forward on this issue, but Daniel needs to deconceptify it.

[ 2009-07-25 Daniel provided non-concepts wording. ]

[ 2009-10 Santa Cruz: ]

Moved to Ready.

Proposed resolution:

  1. Replace the current declaration of fill_n in 27 [algorithms]/2, header <algorithm> synopsis and in 27.7.6 [alg.fill] by

    template<class OutputIterator, class Size, class T>
      voidOutputIterator fill_n(OutputIterator first, Size n, const T& value);
    

    Just after the effects clause add a new returns clause saying:

    Returns: For fill_n and positive n, returns first + n. Otherwise returns first for fill_n.

  2. Replace the current declaration of generate_n in 27 [algorithms]/2, header <algorithm> synopsis and in 27.7.7 [alg.generate] by

    template<class OutputIterator, class Size, class Generator>
      voidOutputIterator generate_n(OutputIterator first, Size n, Generator gen);
    

    Just after the effects clause add a new returns clause saying:

    For generate_n and positive n, returns first + n. Otherwise returns first for generate_n.