[specialized.algorithms] # 26 Algorithms library [[algorithms]](./#algorithms) ## 26.11 Specialized algorithms [specialized.algorithms] ### [26.11.1](#general) General [[specialized.algorithms.general]](specialized.algorithms.general) [1](#general-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13503) The contents specified in [specialized.algorithms] are declared in the header [](memory.syn#header:%3cmemory%3e "20.2.2 Header synopsis [memory.syn]")[.](#general-1.sentence-1) [2](#general-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13507) Unless otherwise specified, if an exception is thrown in the following algorithms, objects constructed by a placement [*new-expression*](expr.new#nt:new-expression "7.6.2.8 New [expr.new]") ([[expr.new]](expr.new "7.6.2.8 New")) are destroyed in an unspecified order before allowing the exception to propagate[.](#general-2.sentence-1) [3](#general-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13514) [*Note [1](#general-note-1)*: When new objects are created by the algorithms specified in [specialized.algorithms], the lifetime ends for any existing objects (including potentially-overlapping subobjects [[intro.object]](intro.object "6.8.2 Object model")) in storage that is reused [[basic.life]](basic.life "6.8.4 Lifetime")[.](#general-3.sentence-1) — *end note*] [4](#general-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13523) Some algorithms specified in [specialized.algorithms] make use of the following exposition-only function templates:templateconstexpr void* *voidify*(T& obj) noexcept {return addressof(obj); }templatedecltype(auto) *deref-move*(I& it) {if constexpr (is_lvalue_reference_v)return std::move(*it); elsereturn *it; } ### [26.11.2](#special.mem.concepts) Special memory concepts [[special.mem.concepts]](special.mem.concepts) [1](#special.mem.concepts-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13543) Some algorithms in this subclause are constrained with the following exposition-only concepts: [🔗](#concept:nothrow-input-iterator) `template concept [nothrow-input-iterator](#concept:nothrow-input-iterator "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") && is_lvalue_reference_v> && [same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")>, iter_value_t>; ` [2](#special.mem.concepts-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13555) A type I models [*nothrow-input-iterator*](#concept:nothrow-input-iterator "26.11.2 Special memory concepts [special.mem.concepts]") only if no exceptions are thrown from increment, copy construction, move construction, copy assignment, move assignment, or indirection through valid iterators[.](#special.mem.concepts-2.sentence-1) [3](#special.mem.concepts-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13562) [*Note [1](#special.mem.concepts-note-1)*: This concept allows some [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") ([[iterator.concept.input]](iterator.concept.input "24.3.4.9 Concept input_­iterator")) operations to throw exceptions[.](#special.mem.concepts-3.sentence-1) — *end note*] [🔗](#concept:nothrow-sentinel-for) `template concept [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") = [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]"); // exposition only ` [4](#special.mem.concepts-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13575) Types S and I model [*nothrow-sentinel-for*](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") only if no exceptions are thrown from copy construction, move construction, copy assignment, move assignment, or comparisons between valid values of type I and S[.](#special.mem.concepts-4.sentence-1) [5](#special.mem.concepts-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13581) [*Note [2](#special.mem.concepts-note-2)*: This concept allows some [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") ([[iterator.concept.sentinel]](iterator.concept.sentinel "24.3.4.7 Concept sentinel_­for")) operations to throw exceptions[.](#special.mem.concepts-5.sentence-1) — *end note*] [🔗](#concept:nothrow-sized-sentinel-for) `template concept [nothrow-sized-sentinel-for](#concept:nothrow-sized-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") && [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]"); ` [6](#special.mem.concepts-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13596) Types S and I model [*nothrow-sized-sentinel-for*](#concept:nothrow-sized-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") only if no exceptions are thrown from the - operator for valid values of type I and S[.](#special.mem.concepts-6.sentence-1) [7](#special.mem.concepts-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13601) [*Note [3](#special.mem.concepts-note-3)*: This concept allows some [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") ([[iterator.concept.sizedsentinel]](iterator.concept.sizedsentinel "24.3.4.8 Concept sized_­sentinel_­for")) operations to throw exceptions[.](#special.mem.concepts-7.sentence-1) — *end note*] [🔗](#concept:nothrow-input-range) `template concept [nothrow-input-range](#concept:nothrow-input-range "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [range](range.range#concept:range "25.4.2 Ranges [range.range]") && [nothrow-input-iterator](#concept:nothrow-input-iterator "26.11.2 Special memory concepts [special.mem.concepts]")> && [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]"), iterator_t>; ` [8](#special.mem.concepts-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13617) A type R models [*nothrow-input-range*](#concept:nothrow-input-range "26.11.2 Special memory concepts [special.mem.concepts]") only if no exceptions are thrown from calls to ranges​::​begin andranges​::​end on an object of type R[.](#special.mem.concepts-8.sentence-1) [🔗](#concept:nothrow-forward-iterator) `template concept [nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-input-iterator](#concept:nothrow-input-iterator "26.11.2 Special memory concepts [special.mem.concepts]") && [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") && [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]"); ` [9](#special.mem.concepts-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13632) [*Note [4](#special.mem.concepts-note-4)*: This concept allows some [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") ([[iterator.concept.forward]](iterator.concept.forward "24.3.4.11 Concept forward_­iterator")) operations to throw exceptions[.](#special.mem.concepts-9.sentence-1) — *end note*] [🔗](#concept:nothrow-forward-range) `template concept [nothrow-forward-range](#concept:nothrow-forward-range "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-input-range](#concept:nothrow-input-range "26.11.2 Special memory concepts [special.mem.concepts]") && [nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]")>; ` [🔗](#concept:nothrow-bidirectional-iterator) `template concept [nothrow-bidirectional-iterator](#concept:nothrow-bidirectional-iterator "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") && [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]"); ` [10](#special.mem.concepts-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13654) A type I models [*nothrow-bidirectional-iterator*](#concept:nothrow-bidirectional-iterator "26.11.2 Special memory concepts [special.mem.concepts]") only if no exceptions are thrown from decrementing valid iterators[.](#special.mem.concepts-10.sentence-1) [*Note [5](#special.mem.concepts-note-5)*: This concept allows some [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") ([[iterator.concept.bidir]](iterator.concept.bidir "24.3.4.12 Concept bidirectional_­iterator")) operations to throw exceptions[.](#special.mem.concepts-10.sentence-2) — *end note*] [🔗](#concept:nothrow-bidirectional-range) `template concept [nothrow-bidirectional-range](#concept:nothrow-bidirectional-range "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-forward-range](#concept:nothrow-forward-range "26.11.2 Special memory concepts [special.mem.concepts]") && [nothrow-bidirectional-iterator](#concept:nothrow-bidirectional-iterator "26.11.2 Special memory concepts [special.mem.concepts]")>; ` [🔗](#concept:nothrow-random-access-iterator) `template concept [nothrow-random-access-iterator](#concept:nothrow-random-access-iterator "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-bidirectional-iterator](#concept:nothrow-bidirectional-iterator "26.11.2 Special memory concepts [special.mem.concepts]") && [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") && [nothrow-sized-sentinel-for](#concept:nothrow-sized-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]"); ` [11](#special.mem.concepts-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13679) A type I models [*nothrow-random-access-iterator*](#concept:nothrow-random-access-iterator "26.11.2 Special memory concepts [special.mem.concepts]") only if no exceptions are thrown from comparisons of valid iterators, or the -, +, -=, +=, [] operators on valid values of type I and iter_difference_t[.](#special.mem.concepts-11.sentence-1) [*Note [6](#special.mem.concepts-note-6)*: This concept allows some [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") ([[iterator.concept.random.access]](iterator.concept.random.access "24.3.4.13 Concept random_­access_­iterator")) operations to throw exceptions[.](#special.mem.concepts-11.sentence-2) — *end note*] [🔗](#special.mem.concepts-itemdecl:10) `template concept [nothrow-random-access-range](#concept:nothrow-random-access-range "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-bidirectional-range](#concept:nothrow-bidirectional-range "26.11.2 Special memory concepts [special.mem.concepts]") && [nothrow-random-access-iterator](#concept:nothrow-random-access-iterator "26.11.2 Special memory concepts [special.mem.concepts]")>; template concept [nothrow-sized-random-access-range](#concept:nothrow-sized-random-access-range "26.11.2 Special memory concepts [special.mem.concepts]") = // exposition only [nothrow-random-access-range](#concept:nothrow-random-access-range "26.11.2 Special memory concepts [special.mem.concepts]") && [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"); ` [12](#special.mem.concepts-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13702) A type R models [*nothrow-sized-random-access-range*](#concept:nothrow-sized-random-access-range "26.11.2 Special memory concepts [special.mem.concepts]") only if no exceptions are thrown from the call to ranges​::​size on an object of type R[.](#special.mem.concepts-12.sentence-1) ### [26.11.3](#uninitialized.construct.default) uninitialized_default_construct [[uninitialized.construct.default]](uninitialized.construct.default) [🔗](#lib:uninitialized_default_construct) `template constexpr void uninitialized_default_construct(NoThrowForwardIterator first, NoThrowForwardIterator last); ` [1](#uninitialized.construct.default-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13718) *Effects*: Equivalent to:for (; first != last; ++first)::new (*voidify*(*first))typename iterator_traits::value_type; [🔗](#lib:uninitialized_default_construct_) `namespace ranges { template<[nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S> requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")> constexpr I uninitialized_default_construct(I first, S last); template<[nothrow-forward-range](#concept:nothrow-forward-range "26.11.2 Special memory concepts [special.mem.concepts]") R> requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")> constexpr borrowed_iterator_t uninitialized_default_construct(R&& r); } ` [2](#uninitialized.construct.default-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13741) *Effects*: Equivalent to:for (; first != last; ++first)::new (*voidify*(*first)) remove_reference_t>;return first; [🔗](#lib:uninitialized_default_construct_n) `template constexpr NoThrowForwardIterator uninitialized_default_construct_n(NoThrowForwardIterator first, Size n); ` [3](#uninitialized.construct.default-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13759) *Effects*: Equivalent to:for (; n > 0; (void)++first, --n)::new (*voidify*(*first))typename iterator_traits::value_type;return first; [🔗](#lib:uninitialized_default_construct_n_) `namespace ranges { template<[nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I> requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")> constexpr I uninitialized_default_construct_n(I first, iter_difference_t n); } ` [4](#uninitialized.construct.default-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13780) *Effects*: Equivalent to:return uninitialized_default_construct(counted_iterator(first, n), default_sentinel).base(); ### [26.11.4](#uninitialized.construct.value) uninitialized_value_construct [[uninitialized.construct.value]](uninitialized.construct.value) [🔗](#lib:uninitialized_value_construct) `template constexpr void uninitialized_value_construct(NoThrowForwardIterator first, NoThrowForwardIterator last); ` [1](#uninitialized.construct.value-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13799) *Effects*: Equivalent to:for (; first != last; ++first)::new (*voidify*(*first))typename iterator_traits::value_type(); [🔗](#lib:uninitialized_value_construct_) `namespace ranges { template<[nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S> requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")> constexpr I uninitialized_value_construct(I first, S last); template<[nothrow-forward-range](#concept:nothrow-forward-range "26.11.2 Special memory concepts [special.mem.concepts]") R> requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")> constexpr borrowed_iterator_t uninitialized_value_construct(R&& r); } ` [2](#uninitialized.construct.value-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13822) *Effects*: Equivalent to:for (; first != last; ++first)::new (*voidify*(*first)) remove_reference_t>();return first; [🔗](#lib:uninitialized_value_construct_n) `template constexpr NoThrowForwardIterator uninitialized_value_construct_n(NoThrowForwardIterator first, Size n); ` [3](#uninitialized.construct.value-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13840) *Effects*: Equivalent to:for (; n > 0; (void)++first, --n)::new (*voidify*(*first))typename iterator_traits::value_type();return first; [🔗](#lib:uninitialized_value_construct_n_) `namespace ranges { template<[nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I> requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")> constexpr I uninitialized_value_construct_n(I first, iter_difference_t n); } ` [4](#uninitialized.construct.value-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13861) *Effects*: Equivalent to:return uninitialized_value_construct(counted_iterator(first, n), default_sentinel).base(); ### [26.11.5](#uninitialized.copy) uninitialized_copy [[uninitialized.copy]](uninitialized.copy) [🔗](#lib:uninitialized_copy) `template constexpr NoThrowForwardIterator uninitialized_copy(InputIterator first, InputIterator last, NoThrowForwardIterator result); ` [1](#uninitialized.copy-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13880) *Preconditions*: result+[0, (last - first)) does not overlap with [first, last)[.](#uninitialized.copy-1.sentence-1) [2](#uninitialized.copy-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13884) *Effects*: Equivalent to:for (; first != last; ++result, (void)++first)::new (*voidify*(*result))typename iterator_traits::value_type(*first); [3](#uninitialized.copy-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13893) *Returns*: result[.](#uninitialized.copy-3.sentence-1) [🔗](#lib:uninitialized_copy_) `namespace ranges { template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") O, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S2> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), iter_reference_t> constexpr uninitialized_copy_result uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") IR, [nothrow-forward-range](#concept:nothrow-forward-range "26.11.2 Special memory concepts [special.mem.concepts]") OR> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), range_reference_t> constexpr uninitialized_copy_result, borrowed_iterator_t> uninitialized_copy(IR&& in_range, OR&& out_range); } ` [4](#uninitialized.copy-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13914) *Preconditions*: [ofirst, olast) does not overlap with [ifirst, ilast)[.](#uninitialized.copy-4.sentence-1) [5](#uninitialized.copy-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13918) *Effects*: Equivalent to:for (; ifirst != ilast && ofirst != olast; ++ofirst, (void)++ifirst)::new (*voidify*(*ofirst)) remove_reference_t>(*ifirst);return {std::move(ifirst), ofirst}; [🔗](#lib:uninitialized_copy_n) `template constexpr NoThrowForwardIterator uninitialized_copy_n(InputIterator first, Size n, NoThrowForwardIterator result); ` [6](#uninitialized.copy-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13936) *Preconditions*: result+[0, n) does not overlap with first+[0, n)[.](#uninitialized.copy-6.sentence-1) [7](#uninitialized.copy-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13940) *Effects*: Equivalent to:for (; n > 0; ++result, (void)++first, --n)::new (*voidify*(*result))typename iterator_traits::value_type(*first); [8](#uninitialized.copy-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13949) *Returns*: result[.](#uninitialized.copy-8.sentence-1) [🔗](#lib:uninitialized_copy_n_) `namespace ranges { template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") O, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), iter_reference_t> constexpr uninitialized_copy_n_result uninitialized_copy_n(I ifirst, iter_difference_t n, O ofirst, S olast); } ` [9](#uninitialized.copy-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13965) *Preconditions*: [ofirst, olast) does not overlap withifirst+[0, n)[.](#uninitialized.copy-9.sentence-1) [10](#uninitialized.copy-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13970) *Effects*: Equivalent to:auto t = uninitialized_copy(counted_iterator(std::move(ifirst), n), default_sentinel, ofirst, olast);return {std::move(t.in).base(), t.out}; ### [26.11.6](#uninitialized.move) uninitialized_move [[uninitialized.move]](uninitialized.move) [🔗](#lib:uninitialized_move) `template constexpr NoThrowForwardIterator uninitialized_move(InputIterator first, InputIterator last, NoThrowForwardIterator result); ` [1](#uninitialized.move-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13990) *Preconditions*: result+[0, (last - first)) does not overlap with [first, last)[.](#uninitialized.move-1.sentence-1) [2](#uninitialized.move-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13994) *Effects*: Equivalent to:for (; first != last; (void)++result, ++first)::new (*voidify*(*result))typename iterator_traits::value_type(*deref-move*(first));return result; [🔗](#lib:uninitialized_move_) `namespace ranges { template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") O, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S2> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), iter_rvalue_reference_t> constexpr uninitialized_move_result uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") IR, [nothrow-forward-range](#concept:nothrow-forward-range "26.11.2 Special memory concepts [special.mem.concepts]") OR> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), range_rvalue_reference_t> constexpr uninitialized_move_result, borrowed_iterator_t> uninitialized_move(IR&& in_range, OR&& out_range); } ` [3](#uninitialized.move-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14021) *Preconditions*: [ofirst, olast) does not overlap with [ifirst, ilast)[.](#uninitialized.move-3.sentence-1) [4](#uninitialized.move-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14025) *Effects*: Equivalent to:for (; ifirst != ilast && ofirst != olast; ++ofirst, (void)++ifirst)::new (*voidify*(*ofirst)) remove_reference_t>(ranges::iter_move(ifirst));return {std::move(ifirst), ofirst}; [5](#uninitialized.move-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14035) [*Note [1](#uninitialized.move-note-1)*: If an exception is thrown, some objects in the range [ifirst, ilast) are left in a valid, but unspecified state[.](#uninitialized.move-5.sentence-1) — *end note*] [🔗](#lib:uninitialized_move_n) `template constexpr pair uninitialized_move_n(InputIterator first, Size n, NoThrowForwardIterator result); ` [6](#uninitialized.move-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14050) *Preconditions*: result+[0, n) does not overlap with first+[0, n)[.](#uninitialized.move-6.sentence-1) [7](#uninitialized.move-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14054) *Effects*: Equivalent to:for (; n > 0; ++result, (void)++first, --n)::new (*voidify*(*result))typename iterator_traits::value_type(*deref-move*(first));return {first, result}; [🔗](#lib:uninitialized_move_n_) `namespace ranges { template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") O, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), iter_rvalue_reference_t> constexpr uninitialized_move_n_result uninitialized_move_n(I ifirst, iter_difference_t n, O ofirst, S olast); } ` [8](#uninitialized.move-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14076) *Preconditions*: [ofirst, olast) does not overlap with ifirst+[0, n)[.](#uninitialized.move-8.sentence-1) [9](#uninitialized.move-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14080) *Effects*: Equivalent to:auto t = uninitialized_move(counted_iterator(std::move(ifirst), n), default_sentinel, ofirst, olast);return {std::move(t.in).base(), t.out}; [10](#uninitialized.move-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14089) [*Note [2](#uninitialized.move-note-2)*: If an exception is thrown, some objects in the rangeifirst+[0, n) are left in a valid but unspecified state[.](#uninitialized.move-10.sentence-1) — *end note*] ### [26.11.7](#uninitialized.fill) uninitialized_fill [[uninitialized.fill]](uninitialized.fill) [🔗](#lib:uninitialized_fill) `template constexpr void uninitialized_fill(NoThrowForwardIterator first, NoThrowForwardIterator last, const T& x); ` [1](#uninitialized.fill-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14107) *Effects*: Equivalent to:for (; first != last; ++first)::new (*voidify*(*first))typename iterator_traits::value_type(x); [🔗](#lib:uninitialized_fill_) `namespace ranges { template<[nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S, class T> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), const T&> constexpr I uninitialized_fill(I first, S last, const T& x); template<[nothrow-forward-range](#concept:nothrow-forward-range "26.11.2 Special memory concepts [special.mem.concepts]") R, class T> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), const T&> constexpr borrowed_iterator_t uninitialized_fill(R&& r, const T& x); } ` [2](#uninitialized.fill-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14130) *Effects*: Equivalent to:for (; first != last; ++first)::new (*voidify*(*first)) remove_reference_t>(x);return first; [🔗](#lib:uninitialized_fill_n) `template constexpr NoThrowForwardIterator uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x); ` [3](#uninitialized.fill-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14148) *Effects*: Equivalent to:for (; n--; ++first)::new (*voidify*(*first))typename iterator_traits::value_type(x);return first; [🔗](#lib:uninitialized_fill_n_) `namespace ranges { template<[nothrow-forward-iterator](#concept:nothrow-forward-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I, class T> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), const T&> constexpr I uninitialized_fill_n(I first, iter_difference_t n, const T& x); } ` [4](#uninitialized.fill-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14169) *Effects*: Equivalent to:return uninitialized_fill(counted_iterator(first, n), default_sentinel, x).base(); ### [26.11.8](#specialized.construct) construct_at [[specialized.construct]](specialized.construct) [🔗](#lib:construct_at) `template constexpr T* construct_at(T* location, Args&&... args); namespace ranges { template constexpr T* construct_at(T* location, Args&&... args); } ` [1](#specialized.construct-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14191) *Constraints*: is_unbounded_array_v is false[.](#specialized.construct-1.sentence-1) The expression ​::​new (declval()) T(declval()...) is well-formed when treated as an unevaluated operand ([[expr.context]](expr.context#term.unevaluated.operand "7.2.3 Context dependence"))[.](#specialized.construct-1.sentence-2) [2](#specialized.construct-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14197) *Mandates*: If is_array_v is true, sizeof...(Args) is zero[.](#specialized.construct-2.sentence-1) [3](#specialized.construct-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14201) *Effects*: Equivalent to:if constexpr (is_array_v)return ::new (*voidify*(*location)) T[1]();elsereturn ::new (*voidify*(*location)) T(std::forward(args)...); ### [26.11.9](#specialized.destroy) destroy [[specialized.destroy]](specialized.destroy) [🔗](#lib:destroy_at) `template constexpr void destroy_at(T* location); namespace ranges { template<[destructible](concept.destructible#concept:destructible "18.4.10 Concept destructible [concept.destructible]") T> constexpr void destroy_at(T* location) noexcept; } ` [1](#specialized.destroy-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14225) *Effects*: - [(1.1)](#specialized.destroy-1.1) If T is an array type, equivalent to destroy(begin(*location), end(*location))[.](#specialized.destroy-1.1.sentence-1) - [(1.2)](#specialized.destroy-1.2) Otherwise, equivalent to location->~T()[.](#specialized.destroy-1.2.sentence-1) [🔗](#lib:destroy) `template constexpr void destroy(NoThrowForwardIterator first, NoThrowForwardIterator last); ` [2](#specialized.destroy-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14242) *Effects*: Equivalent to:for (; first != last; ++first) destroy_at(addressof(*first)); [🔗](#lib:destroy_) `namespace ranges { template<[nothrow-input-iterator](#concept:nothrow-input-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I, [nothrow-sentinel-for](#concept:nothrow-sentinel-for "26.11.2 Special memory concepts [special.mem.concepts]") S> requires [destructible](concept.destructible#concept:destructible "18.4.10 Concept destructible [concept.destructible]")> constexpr I destroy(I first, S last) noexcept; template<[nothrow-input-range](#concept:nothrow-input-range "26.11.2 Special memory concepts [special.mem.concepts]") R> requires [destructible](concept.destructible#concept:destructible "18.4.10 Concept destructible [concept.destructible]")> constexpr borrowed_iterator_t destroy(R&& r) noexcept; } ` [3](#specialized.destroy-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14264) *Effects*: Equivalent to:for (; first != last; ++first) destroy_at(addressof(*first));return first; [🔗](#lib:destroy_n) `template constexpr NoThrowForwardIterator destroy_n(NoThrowForwardIterator first, Size n); ` [4](#specialized.destroy-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14281) *Effects*: Equivalent to:for (; n > 0; (void)++first, --n) destroy_at(addressof(*first));return first; [🔗](#lib:destroy_n_) `namespace ranges { template<[nothrow-input-iterator](#concept:nothrow-input-iterator "26.11.2 Special memory concepts [special.mem.concepts]") I> requires [destructible](concept.destructible#concept:destructible "18.4.10 Concept destructible [concept.destructible]")> constexpr I destroy_n(I first, iter_difference_t n) noexcept; } ` [5](#specialized.destroy-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14301) *Effects*: Equivalent to:return destroy(counted_iterator(std::move(first), n), default_sentinel).base();