1. Changelog
-
R0
-
First submission
-
2. Motivation and scope
[P2283R2] ("constexpr for specialized memory algorithms") proposes to
add
to most specialized memory algorithms:
-
;uninitialized_value_construct -
;uninitialized_copy -
;uninitialized_move -
.uninitialized_fill
All the overloads of these algorithms in namespaces
and
, as well as their
variants, are affected by [P2283R2]; the only exceptions are the parallel overloads (cf. [P2902R0], "
Parallel Algorithms").
One algorithm family is missing:
. The
reason for it is that it was impossible to perform default construction
in a constexpr context;
always performs value initialization, and indeed, all the proposed algorithms are specified
in terms of calls to
.
With the adoption of [P2747R2] ("
placement new") it is
now possible to perform such default construction during constant
evaluation, without the need of changing how
is specified. Therefore, this paper
simply proposes to add
to those algorithms.
3. Impact on the Standard
This proposal is a pure library addition. The necessary changes to core language have already been adopted.
4. Proposed Wording
All the proposed changes are relative to [N4986].
4.1. Feature-testing macro
In [version.syn], modify the value of the
to match the date of adoption of the present proposal.
4.2. Wording
Modify [memory.syn] as follows:
template < class NoThrowForwardIterator > constexpr void uninitialized_default_construct ( NoThrowForwardIterator first , // freestanding NoThrowForwardIterator last ); template < class ExecutionPolicy , class NoThrowForwardIterator > void uninitialized_default_construct ( ExecutionPolicy && exec , // see [algorithms.parallel.overloads] NoThrowForwardIterator first , NoThrowForwardIterator last ); template < class NoThrowForwardIterator , class Size > constexpr NoThrowForwardIterator uninitialized_default_construct_n ( NoThrowForwardIterator first , Size n ); // freestanding template < class ExecutionPolicy , class NoThrowForwardIterator , class Size > NoThrowForwardIterator uninitialized_default_construct_n ( ExecutionPolicy && exec , // see [algorithms.parallel.overloads] NoThrowForwardIterator first , Size n ); namespace ranges { template < nothrow - forward - iterator I , nothrow - sentinel - for < I > S > requires default_initializable < iter_value_t < I >> constexpr I uninitialized_default_construct ( I first , S last ); // freestanding template < nothrow - forward - range R > requires default_initializable < range_value_t < R >> constexpr borrowed_iterator_t < R > uninitialized_default_construct ( R && r ); // freestanding template < nothrow - forward - iterator I > requires default_initializable < iter_value_t < I >> constexpr I uninitialized_default_construct_n ( I first , iter_difference_t < I > n ); // freestanding }
Modify [uninitialized.construct.default] as follows:
template < class NoThrowForwardIterator > constexpr void uninitialized_default_construct ( NoThrowForwardIterator first , NoThrowForwardIterator last );
namespace ranges { template < nothrow - forward - iterator I , nothrow - sentinel - for < I > S > requires default_initializable < iter_value_t < I >> constexpr I uninitialized_default_construct ( I first , S last ); template < nothrow - forward - range R > requires default_initializable < range_value_t < R >> constexpr borrowed_iterator_t < R > uninitialized_default_construct ( R && r ); }
template < class NoThrowForwardIterator , class Size > constexpr NoThrowForwardIterator uninitialized_default_construct_n ( NoThrowForwardIterator first , Size n );
namespace ranges { template < nothrow - forward - iterator I > requires default_initializable < iter_value_t < I >> constexpr I uninitialized_default_construct_n ( I first , iter_difference_t < I > n ); }
5. Acknowledgements
Thanks to Michael Schellenberger Costa for [P2283R2] and Barry Revzin for [P2747R2].
Thanks to KDAB for supporting this work.
All remaining errors are ours and ours only.