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.
Section: 26.7.6 [alg.fill], 26.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) 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:
template<class OutputIterator, class Size, class T> void fill_n(OutputIterator first, Size n, const T& value);
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
24.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:
Replace the current declaration of fill_n
in 26 [algorithms]/2, header
<algorithm>
synopsis and in 26.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 positiven
, returnsfirst + n
. Otherwise returnsfirst
forfill_n
.
Replace the current declaration of generate_n
in 26 [algorithms]/2,
header <algorithm>
synopsis and in 26.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 positiven
, returnsfirst + n
. Otherwise returnsfirst
forgenerate_n
.