Title
More algorithms that throw away information
Status
c++11
Section
[alg.fill][alg.generate]
Submitter
Daniel Krügler

Created on 2008-07-13.00:00:00 last changed 161 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

  1. Replace the current declaration of fill_n in [algorithms]/2, header <algorithm> synopsis and in [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 [algorithms]/2, header <algorithm> synopsis and in [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.

Date: 2010-10-21.18:28:33

[ 2009-10 Santa Cruz: ]

Moved to Ready.

Date: 2009-07-25.00:00:00

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

Date: 2010-10-21.18:28:33

[ 2009-07 Frankfurt ]

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

Date: 2010-10-21.18:28:33

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

Date: 2010-10-21.18:28:33

[ Post Summit Daniel "conceptualized" the wording. ]

Date: 2011-04-28.21:34:33

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

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg4117
2010-10-21 18:28:33adminsetmessages: + msg4116
2010-10-21 18:28:33adminsetmessages: + msg4115
2010-10-21 18:28:33adminsetmessages: + msg4114
2010-10-21 18:28:33adminsetmessages: + msg4113
2010-10-21 18:28:33adminsetmessages: + msg4112
2008-07-13 00:00:00admincreate