This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
.venv
*.pyc
*.html
raw

1
.python-version Normal file
View File

@@ -0,0 +1 @@
3.12

45
cppdraft/accumulate.md Normal file
View File

@@ -0,0 +1,45 @@
[accumulate]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#accumulate)
### 26.10.3 Accumulate [accumulate]
[🔗](#lib:accumulate)
`template<class InputIterator, class T>
constexpr T accumulate(InputIterator first, InputIterator last, T init);
template<class InputIterator, class T, class BinaryOperation>
constexpr T accumulate(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12302)
*Preconditions*: T meets
the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#1.sentence-1)
In the range [first, last],binary_op neither modifies elements
nor invalidates iterators or subranges[.](#1.sentence-2)[205](#footnote-205 "The use of fully closed ranges is intentional.")
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12314)
*Effects*: Computes its result by
initializing the accumulator acc with the initial value init and then modifies it withacc = std::move(acc) + *i oracc = binary_op(std::move(acc), *i) for every iterator i in the range [first, last) in order[.](#2.sentence-1)[206](#footnote-206 "accumulate is similar to the APL reduction operator and Common Lisp reduce function, but it avoids the difficulty of defining the result of reduction on an empty sequence by always requiring an initial value.")
[205)](#footnote-205)[205)](#footnoteref-205)
The use of fully closed ranges is intentional[.](#footnote-205.sentence-1)
[206)](#footnote-206)[206)](#footnoteref-206)
accumulate is similar
to the APL reduction operator and Common Lisp reduce function,
but it avoids the difficulty of defining the result of reduction
on an empty sequence by always requiring an initial value[.](#footnote-206.sentence-1)

View File

@@ -0,0 +1,128 @@
[adjacent.difference]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#adjacent.difference)
### 26.10.12 Adjacent difference [adjacent.difference]
[🔗](#lib:adjacent_difference)
`template<class InputIterator, class OutputIterator>
constexpr OutputIterator
adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
adjacent_difference(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);
template<class InputIterator, class OutputIterator, class BinaryOperation>
constexpr OutputIterator
adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryOperation>
ForwardIterator2
adjacent_difference(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, BinaryOperation binary_op);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13139)
Let T be the value type of decltype(first)[.](#1.sentence-1)
For the overloads that do not take an argument binary_op,
let binary_op be an lvalue
that denotes an object of type minus<>[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13145)
*Mandates*:
- [(2.1)](#2.1)
For the overloads with no ExecutionPolicy, T is constructible from *first[.](#2.1.sentence-1)
acc (defined below) is
writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General"))
to the result output iterator[.](#2.1.sentence-2)
The result of the expression binary_op(val, std::move(acc)) is writable to result[.](#2.1.sentence-3)
- [(2.2)](#2.2)
For the overloads with an ExecutionPolicy,
the result of the expressions binary_op(*first, *first) and *first are writable to result[.](#2.2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13162)
*Preconditions*:
- [(3.1)](#3.1)
For the overloads with no ExecutionPolicy, T meets the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements"))
requirements[.](#3.1.sentence-1)
- [(3.2)](#3.2)
For all overloads, in the ranges [first, last]
and [result, result + (last - first)], binary_op neither modifies elements
nor invalidates iterators or subranges[.](#3.2.sentence-1)[209](#footnote-209 "The use of fully closed ranges is intentional.")
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13179)
*Effects*: For the overloads with no ExecutionPolicy and a non-empty range,
the function creates an accumulator acc of type T,
initializes it with *first,
and assigns the result to *result[.](#4.sentence-1)
For every iterator i in [first + 1, last) in order,
creates an object val whose type is T,
initializes it with *i,
computes binary_op(val, std::move(acc)),
assigns the result to *(result + (i - first)), and
move assigns from val to acc[.](#4.sentence-2)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13192)
For the overloads with an ExecutionPolicy and a non-empty range,
performs *result = *first[.](#5.sentence-1)
Then, for every d in [1, last - first - 1],
performs *(result + d) = binary_op(*(first + d), *(first + (d - 1)))[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13198)
*Returns*: result + (last - first)[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13202)
*Complexity*: Exactly (last - first) - 1 applications of the binary operation[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13206)
*Remarks*: For the overloads with no ExecutionPolicy,result may be equal to first[.](#8.sentence-1)
For the overloads with an ExecutionPolicy,
the ranges [first, last) and [result, result + (last - first))
shall not overlap[.](#8.sentence-2)
[209)](#footnote-209)[209)](#footnoteref-209)
The use of fully closed ranges is intentional[.](#footnote-209.sentence-1)

View File

@@ -0,0 +1,67 @@
[adjustfield.manip]
# 31 Input/output library [[input.output]](./#input.output)
## 31.5 Iostreams base classes [[iostreams.base]](iostreams.base#adjustfield.manip)
### 31.5.5 ios_base manipulators [[std.ios.manip]](std.ios.manip#adjustfield.manip)
#### 31.5.5.2 adjustfield manipulators [adjustfield.manip]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L2631)
Each function specified in this subclause
is a designated addressable function ([[namespace.std]](namespace.std "16.4.5.2.1Namespace std"))[.](#1.sentence-1)
[🔗](#lib:internal)
`ios_base& internal(ios_base& str);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L2641)
*Effects*: Callsstr.setf(ios_base::internal, ios_base::adjustfield)[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L2646)
*Returns*: str[.](#3.sentence-1)
[🔗](#lib:left)
`ios_base& left(ios_base& str);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L2657)
*Effects*: Callsstr.setf(ios_base::left, ios_base::adjustfield)[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L2662)
*Returns*: str[.](#5.sentence-1)
[🔗](#lib:right)
`ios_base& right(ios_base& str);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L2673)
*Effects*: Callsstr.setf(ios_base::right, ios_base::adjustfield)[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L2678)
*Returns*: str[.](#7.sentence-1)

View File

@@ -0,0 +1,87 @@
[alg.adjacent.find]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.adjacent.find)
### 26.6.10 Adjacent find [alg.adjacent.find]
[🔗](#lib:adjacent_find)
`template<class ForwardIterator>
constexpr ForwardIterator
adjacent_find(ForwardIterator first, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator
adjacent_find(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class BinaryPredicate>
constexpr ForwardIterator
adjacent_find(ForwardIterator first, ForwardIterator last,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
ForwardIterator
adjacent_find(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
BinaryPredicate pred);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>,
projected<I, Proj>> Pred = ranges::equal_to>
constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>,
projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
constexpr borrowed_iterator_t<R> ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>,
projected<I, Proj>> Pred = ranges::equal_to>
I ranges::adjacent_find(Ep&& exec, I first, S last, Pred pred = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>,
projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
borrowed_iterator_t<R>
ranges::adjacent_find(Ep&& exec, R&& r, Pred pred = {}, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5346)
Let E be:
- [(1.1)](#1.1)
*i == *(i + 1) for the overloads with no parameter pred;
- [(1.2)](#1.2)
pred(*i, *(i + 1)) != false for the overloads with a parameter pred and no parameter proj;
- [(1.3)](#1.3)
bool(invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1)))) for the overloads with both parameters pred and proj[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5355)
*Returns*: The first iterator i such that both i and i + 1 are in the range [first, last)
for which E holds[.](#2.sentence-1)
Returns last if no such iterator is found[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5362)
*Complexity*: For the non-parallel algorithm overloads,
exactly min((i - first) + 1, (last - first) - 1) applications of the corresponding predicate,
where i is adjacent_find's return value[.](#3.sentence-1)
For the parallel algorithm overloads,O(last - first) applications of the corresponding predicate[.](#3.sentence-2)
No more than twice as many applications of any projection[.](#3.sentence-3)

56
cppdraft/alg/all/of.md Normal file
View File

@@ -0,0 +1,56 @@
[alg.all.of]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.all.of)
### 26.6.1 All of [alg.all.of]
[🔗](#lib:all_of)
`template<class InputIterator, class Predicate>
constexpr bool all_of(InputIterator first, InputIterator last, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
bool ranges::all_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
bool ranges::all_of(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4408)
Let E be:
- [(1.1)](#1.1)
pred(*i) for the overloads in namespace std;
- [(1.2)](#1.2)
invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4418)
*Returns*: false if E is false for some iterator i in the range [first, last), andtrue otherwise[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4424)
*Complexity*: At most last - first applications of the predicate and any projection[.](#3.sentence-1)

57
cppdraft/alg/any/of.md Normal file
View File

@@ -0,0 +1,57 @@
[alg.any.of]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.any.of)
### 26.6.2 Any of [alg.any.of]
[🔗](#lib:any_of)
`template<class InputIterator, class Predicate>
constexpr bool any_of(InputIterator first, InputIterator last, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
bool ranges::any_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
bool ranges::any_of(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4455)
Let E be:
- [(1.1)](#1.1)
pred(*i) for the overloads in namespace std;
- [(1.2)](#1.2)
invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4465)
*Returns*: true if E is true for some iterator i in the range [first, last), and false otherwise[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4470)
*Complexity*: At most last - first applications of the predicate
and any projection[.](#3.sentence-1)

View File

@@ -0,0 +1,260 @@
[alg.binary.search]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.binary.search)
### 26.8.4 Binary search [alg.binary.search]
#### [26.8.4.1](#general) General [[alg.binary.search.general]](alg.binary.search.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9395)
All of the algorithms in [alg.binary.search] are versions of binary search and
assume that the sequence being searched
is partitioned with respect to an expression
formed by binding the search key to an argument of the comparison function[.](#general-1.sentence-1)
They work on non-random access iterators minimizing the number of comparisons,
which will be logarithmic for all types of iterators[.](#general-1.sentence-2)
They are especially appropriate for random access iterators,
because these algorithms do a logarithmic number of steps
through the data structure[.](#general-1.sentence-3)
For non-random access iterators they execute a linear number of steps[.](#general-1.sentence-4)
#### [26.8.4.2](#lower.bound) lower_bound [[lower.bound]](lower.bound)
[🔗](#lib:lower_bound)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last,
const T& value);
template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type,
class Compare>
constexpr ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last,
const T& value, Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<I, Proj>> Comp = ranges::less>
constexpr I ranges::lower_bound(I first, S last, const T& value, Comp comp = {},
Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<iterator_t<R>, Proj>> Comp =
ranges::less>
constexpr borrowed_iterator_t<R>
ranges::lower_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {});
`
[1](#lower.bound-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9436)
Let comp be less{} andproj be identity{} for overloads with no parameters by those names[.](#lower.bound-1.sentence-1)
[2](#lower.bound-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9441)
*Preconditions*: The elements e of [first, last)
are partitioned with respect to the expression
bool(invoke(comp, invoke(proj, e), value))[.](#lower.bound-2.sentence-2)
[3](#lower.bound-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9447)
*Returns*: The furthermost iterator i in the range [first, last]
such that for every iterator j in the range [first, i),bool(invoke(comp, invoke(proj, *j), value)) is true[.](#lower.bound-3.sentence-1)
[4](#lower.bound-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9453)
*Complexity*: At most log2(last - first)+O(1) comparisons and projections[.](#lower.bound-4.sentence-1)
#### [26.8.4.3](#upper.bound) upper_bound [[upper.bound]](upper.bound)
[🔗](#lib:upper_bound)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last,
const T& value);
template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type,
class Compare>
constexpr ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last,
const T& value, Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<I, Proj>> Comp = ranges::less>
constexpr I ranges::upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<iterator_t<R>, Proj>> Comp =
ranges::less>
constexpr borrowed_iterator_t<R>
ranges::upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {});
`
[1](#upper.bound-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9486)
Let comp be less{} andproj be identity{} for overloads with no parameters by those names[.](#upper.bound-1.sentence-1)
[2](#upper.bound-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9491)
*Preconditions*: The elements e of [first, last)
are partitioned with respect to the expression
!bool(invoke(comp, value, invoke(proj, e)))[.](#upper.bound-2.sentence-2)
[3](#upper.bound-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9497)
*Returns*: The furthermost iterator i in the range [first, last]
such that for every iterator j in the range [first, i),!bool(invoke(comp, value, invoke(proj, *j))) is true[.](#upper.bound-3.sentence-1)
[4](#upper.bound-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9503)
*Complexity*: At most log2(last - first)+O(1) comparisons and projections[.](#upper.bound-4.sentence-1)
#### [26.8.4.4](#equal.range) equal_range [[equal.range]](equal.range)
[🔗](#lib:equal_range)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first,
ForwardIterator last, const T& value);
template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type,
class Compare>
constexpr pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first,
ForwardIterator last, const T& value,
Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<I, Proj>> Comp = ranges::less>
constexpr subrange<I>
ranges::equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<iterator_t<R>, Proj>> Comp =
ranges::less>
constexpr borrowed_subrange_t<R>
ranges::equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {});
`
[1](#equal.range-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9538)
Let comp be less{} andproj be identity{} for overloads with no parameters by those names[.](#equal.range-1.sentence-1)
[2](#equal.range-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9543)
*Preconditions*: The elements e of [first, last)
are partitioned with respect to the expressionsbool(invoke(comp, invoke(proj, e), value)) and!bool(invoke(comp, value, invoke(proj, e)))[.](#equal.range-2.sentence-1)
Also, for all elements e of [first, last),bool(comp(e, value)) implies !bool(comp(value, e)) for the overloads in namespace std[.](#equal.range-2.sentence-2)
[3](#equal.range-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9553)
*Returns*:
- [(3.1)](#equal.range-3.1)
For the overloads in namespace std:{lower_bound(first, last, value, comp),
upper_bound(first, last, value, comp)}
- [(3.2)](#equal.range-3.2)
For the overloads in namespace ranges:{ranges::lower_bound(first, last, value, comp, proj),
ranges::upper_bound(first, last, value, comp, proj)}
[4](#equal.range-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9570)
*Complexity*: At most2∗log2(last - first)+O(1) comparisons and projections[.](#equal.range-4.sentence-1)
#### [26.8.4.5](#binary.search) binary_search [[binary.search]](binary.search)
[🔗](#lib:binary_search)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr bool
binary_search(ForwardIterator first, ForwardIterator last,
const T& value);
template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type,
class Compare>
constexpr bool
binary_search(ForwardIterator first, ForwardIterator last,
const T& value, Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<I, Proj>> Comp = ranges::less>
constexpr bool ranges::binary_search(I first, S last, const T& value, Comp comp = {},
Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<const T*, projected<iterator_t<R>, Proj>> Comp =
ranges::less>
constexpr bool ranges::binary_search(R&& r, const T& value, Comp comp = {},
Proj proj = {});
`
[1](#binary.search-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9605)
Let comp be less{} andproj be identity{} for overloads with no parameters by those names[.](#binary.search-1.sentence-1)
[2](#binary.search-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9610)
*Preconditions*: The elements e of [first, last)
are partitioned with respect to the expressionsbool(invoke(comp, invoke(proj, e), value)) and!bool(invoke(comp, value, invoke(proj, e)))[.](#binary.search-2.sentence-1)
Also, for all elements e of [first, last),bool(comp(e, value)) implies !bool(comp(value, e)) for the overloads in namespace std[.](#binary.search-2.sentence-2)
[3](#binary.search-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9620)
*Returns*: true if and only if
for some iterator i in the range [first, last),!bool(invoke(comp, invoke(proj, *i), value)) &&!bool(invoke(comp, value, invoke(proj, *i))) is true[.](#binary.search-3.sentence-1)
[4](#binary.search-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9628)
*Complexity*: At most log2(last - first)+O(1) comparisons and projections[.](#binary.search-4.sentence-1)

View File

@@ -0,0 +1,27 @@
[alg.binary.search.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.binary.search.general)
### 26.8.4 Binary search [[alg.binary.search]](alg.binary.search#general)
#### 26.8.4.1 General [alg.binary.search.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9395)
All of the algorithms in [[alg.binary.search]](alg.binary.search "26.8.4Binary search") are versions of binary search and
assume that the sequence being searched
is partitioned with respect to an expression
formed by binding the search key to an argument of the comparison function[.](#1.sentence-1)
They work on non-random access iterators minimizing the number of comparisons,
which will be logarithmic for all types of iterators[.](#1.sentence-2)
They are especially appropriate for random access iterators,
because these algorithms do a logarithmic number of steps
through the data structure[.](#1.sentence-3)
For non-random access iterators they execute a linear number of steps[.](#1.sentence-4)

49
cppdraft/alg/c/library.md Normal file
View File

@@ -0,0 +1,49 @@
[alg.c.library]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.13 C library algorithms [alg.c.library]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14449)
[*Note [1](#note-1)*:
The header [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2Header <cstdlib> synopsis[cstdlib.syn]") declares the functions described in this subclause[.](#1.sentence-1)
— *end note*]
[🔗](#lib:bsearch)
`void* bsearch(const void* key, void* base, size_t nmemb, size_t size,
c-compare-pred* compar);
void* bsearch(const void* key, void* base, size_t nmemb, size_t size,
compare-pred* compar);
const void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
c-compare-pred* compar);
const void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
compare-pred* compar);
void qsort(void* base, size_t nmemb, size_t size, c-compare-pred* compar);
void qsort(void* base, size_t nmemb, size_t size, compare-pred* compar);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14471)
*Preconditions*: For qsort, the objects in the array pointed to by base are of trivially copyable type[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14476)
*Effects*: These functions have the semantics specified in the C standard library[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14480)
*Throws*: Any exception thrown by compar ([[res.on.exception.handling]](res.on.exception.handling "16.4.6.14Restrictions on exception handling"))[.](#4.sentence-1)
See also: ISO/IEC 9899:2024, 7.24.5

57
cppdraft/alg/clamp.md Normal file
View File

@@ -0,0 +1,57 @@
[alg.clamp]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.clamp)
### 26.8.10 Bounded value [alg.clamp]
[🔗](#lib:clamp)
`template<class T>
constexpr const T& clamp(const T& v, const T& lo, const T& hi);
template<class T, class Compare>
constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
template<class T, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<const T*, Proj>> Comp = ranges::less>
constexpr const T&
ranges::clamp(const T& v, const T& lo, const T& hi, Comp comp = {}, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11714)
Let comp be less{} for the overloads with no parameter comp,
and let proj be identity{} for the overloads with no parameter proj[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11720)
*Preconditions*: bool(invoke(comp, invoke(proj, hi), invoke(proj, lo))) is false[.](#2.sentence-1)
For the first form, type T meets the [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11727)
*Returns*: lo if bool(invoke(comp, invoke(proj, v), invoke(proj, lo))) is true,hi if bool(invoke(comp, invoke(proj, hi), invoke(proj, v))) is true,
otherwise v[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11733)
[*Note [1](#note-1)*:
If NaN is avoided, T can be a floating-point type[.](#4.sentence-1)
— *end note*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11738)
*Complexity*: At most two comparisons and three applications of the projection[.](#5.sentence-1)

87
cppdraft/alg/contains.md Normal file
View File

@@ -0,0 +1,87 @@
[alg.contains]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.contains)
### 26.6.4 Contains [alg.contains]
[🔗](#lib:contains)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4537)
*Returns*: ranges::find(std::move(first), last, value, proj) != last[.](#1.sentence-1)
[🔗](#itemdecl:2)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
bool ranges::contains(Ep&& exec, I first, S last, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
bool ranges::contains(Ep&& exec, R&& r, const T& value, Proj proj = {});
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4555)
*Returns*: ranges::find(std::forward<Ep>(exec), first, last, value, proj) != last[.](#2.sentence-1)
[🔗](#lib:contains_subrange)
`template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1,
[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr bool ranges::contains_subrange(I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr bool ranges::contains_subrange(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4576)
*Returns*: first2 == last2 || !ranges::search(first1, last1, first2, last2,
pred, proj1, proj2).empty()
[🔗](#itemdecl:4)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
bool ranges::contains_subrange(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
bool ranges::contains_subrange(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4599)
*Returns*: first2 == last2 || !ranges::search(std::forward<Ep>(exec), first1, last1,
first2, last2, pred, proj1, proj2).empty()

401
cppdraft/alg/copy.md Normal file
View File

@@ -0,0 +1,401 @@
[alg.copy]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.copy)
### 26.7.1 Copy [alg.copy]
[🔗](#lib:copy)
`template<class InputIterator, class OutputIterator>
constexpr OutputIterator copy(InputIterator first, InputIterator last,
OutputIterator result);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O>
constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6361)
Let N be last - first[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6364)
*Preconditions*: result is not in the range [first, last)[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6368)
*Effects*: Copies elements in the range [first, last)
into the range [result, result + N)
starting from first and proceeding to last[.](#3.sentence-1)
For each non-negative integer n<N,
performs *(result + n) = *(first + n)[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6376)
*Returns*:
- [(4.1)](#4.1)
result + N for the overload in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{last, result + N} for the overloads in namespace ranges[.](#4.2.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6385)
*Complexity*: Exactly N assignments[.](#5.sentence-1)
[🔗](#lib:copy_)
`template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2 copy(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
ranges::copy_result<I, O>
ranges::copy(Ep&& exec, I first, S last, O result, OutS result_last);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>>
ranges::copy_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::copy(Ep&& exec, R&& r, OutR&& result_r);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6409)
Let result_last be result + (last - first) for the overload in namespace std[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6413)
Let N be min(last - first, result_last - result)[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6416)
*Preconditions*: The ranges [first, last) and [result, result + N)
do not overlap[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6421)
*Effects*: Copies elements in the range [first, first + N)
into the range [result, result + N)[.](#9.sentence-1)
For each non-negative integer n<N,
performs *(result + n) = *(first + n)[.](#9.sentence-2)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6428)
*Returns*:
- [(10.1)](#10.1)
result + N for the overload in namespace std[.](#10.1.sentence-1)
- [(10.2)](#10.2)
{first + N, result + N} for the overloads in namespace ranges[.](#10.2.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6437)
*Complexity*: Exactly N assignments[.](#11.sentence-1)
[🔗](#lib:copy_n)
`template<class InputIterator, class Size, class OutputIterator>
constexpr OutputIterator copy_n(InputIterator first, Size n,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
ForwardIterator2 copy_n(ExecutionPolicy&& exec,
ForwardIterator1 first, Size n,
ForwardIterator2 result);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
constexpr ranges::copy_n_result<I, O>
ranges::copy_n(I first, iter_difference_t<I> n, O result);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O,
[sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
ranges::copy_n_result<I, O>
ranges::copy_n(Ep&& exec, I first, iter_difference_t<I> n, O result, OutS result_last);
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6465)
Let M be max(0, n)[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6468)
Let result_last be result + M for the overloads with no parameter result_last[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6472)
Let N be min(result_last - result,M)[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6475)
*Mandates*: The type Size is convertible
to an integral type ([[conv.integral]](conv.integral "7.3.9Integral conversions"), [[class.conv]](class.conv "11.4.8Conversions"))[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6480)
*Effects*: For each non-negative integer i<N,
performs *(result + i) = *(first + i)[.](#16.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6485)
*Returns*:
- [(17.1)](#17.1)
result + N for the overloads in namespace std[.](#17.1.sentence-1)
- [(17.2)](#17.2)
{first + N, result + N} for the overload in namespace ranges[.](#17.2.sentence-1)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6496)
*Complexity*: Exactly N assignments[.](#18.sentence-1)
[🔗](#lib:copy_if)
`template<class InputIterator, class OutputIterator, class Predicate>
constexpr OutputIterator copy_if(InputIterator first, InputIterator last,
OutputIterator result, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class Predicate>
ForwardIterator2 copy_if(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
constexpr ranges::copy_if_result<I, O>
ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O>
constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
ranges::copy_if_result<I, O>
ranges::copy_if(Ep&& exec, I first, S last, O result, OutS result_last,
Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR,
class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>>
ranges::copy_if_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::copy_if(Ep&& exec, R&& r, OutR&& result_r, Pred pred, Proj proj = {});
`
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6539)
Let E(i) be:
- [(19.1)](#19.1)
bool(pred(*i)) for the overloads in namespace std;
- [(19.2)](#19.2)
bool(invoke(pred, invoke(proj, *i))) for the overloads in namespace ranges[.](#19.sentence-1)
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6550)
Let:
- [(20.1)](#20.1)
M be the number of iterators i in the range [first, last)
for which the condition E(i) holds;
- [(20.2)](#20.2)
result_last be result + M for the overloads with no parameter result_last or result_r;
- [(20.3)](#20.3)
N be min(M, result_last - result)[.](#20.sentence-1)
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6563)
*Preconditions*: The ranges [first, last) and [result, result + N)
do not overlap[.](#21.sentence-1)
[*Note [1](#note-1)*:
For the parallel algorithm overload in namespace std,
there can be a performance cost
if iterator_traits<ForwardIterator1>::value_type does not meet the *Cpp17MoveConstructible* (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) requirements[.](#21.sentence-2)
For the parallel algorithm overloads in namespace ranges,
there can be a performance cost
if iter_value_t<I> does not model [move_constructible](concept.moveconstructible#concept:move_constructible "18.4.13Concept move_­constructible[concept.moveconstructible]")[.](#21.sentence-3)
— *end note*]
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6577)
*Effects*: Copies the first N elements referred to
by the iterator i in the range [first, last)
for which E(i) is true into the range [result, result + N)[.](#22.sentence-1)
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6584)
*Returns*:
- [(23.1)](#23.1)
result + N for the overloads in namespace std[.](#23.1.sentence-1)
- [(23.2)](#23.2)
{last, result + N} for the overloads in namespace ranges, if N is equal to M[.](#23.2.sentence-1)
- [(23.3)](#23.3)
Otherwise, {j, result_last} for the overloads in namespace ranges,
where j is the iterator in [first, last)
for which E(j) holds
and there are exactly N iterators i in [first, j) for which E(i) holds[.](#23.3.sentence-1)
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6602)
*Complexity*: At most last - first applications
of the corresponding predicate and any projection[.](#24.sentence-1)
[25](#25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6607)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#25.sentence-1)
[🔗](#lib:copy_backward)
`template<class BidirectionalIterator1, class BidirectionalIterator2>
constexpr BidirectionalIterator2
copy_backward(BidirectionalIterator1 first,
BidirectionalIterator1 last,
BidirectionalIterator2 result);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I2>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I1, I2>
constexpr ranges::copy_backward_result<I1, I2>
ranges::copy_backward(I1 first, S1 last, I2 result);
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, I>
constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
ranges::copy_backward(R&& r, I result);
`
[26](#26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6631)
Let N be last - first[.](#26.sentence-1)
[27](#27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6634)
*Preconditions*: result is not in the range (first, last][.](#27.sentence-1)
[28](#28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6638)
*Effects*: Copies elements in the range [first, last)
into the range [result - N, result)
starting from last - 1 and proceeding to first[.](#28.sentence-1)[201](#footnote-201 "copy_­backward can be used instead of copy when last is in the range [result - N, result).")
For each positive integer n ≤ N,
performs *(result - n) = *(last - n)[.](#28.sentence-2)
[29](#29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6650)
*Returns*:
- [(29.1)](#29.1)
result - N for the overload in namespace std[.](#29.1.sentence-1)
- [(29.2)](#29.2)
{last, result - N} for the overloads in namespace ranges[.](#29.2.sentence-1)
[30](#30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6661)
*Complexity*: Exactly N assignments[.](#30.sentence-1)
[201)](#footnote-201)[201)](#footnoteref-201)
copy_backward can be used instead of copy when last is in the range [result - N, result)[.](#footnote-201.sentence-1)

106
cppdraft/alg/count.md Normal file
View File

@@ -0,0 +1,106 @@
[alg.count]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.count)
### 26.6.11 Count [alg.count]
[🔗](#lib:count)
`template<class InputIterator, class T = iterator_traits<InputIterator>::value_type>
constexpr typename iterator_traits<InputIterator>::difference_type
count(InputIterator first, InputIterator last, const T& value);
template<class ExecutionPolicy, class ForwardIterator,
class T = iterator_traits<ForwardIterator>::value_type>
typename iterator_traits<ForwardIterator>::difference_type
count(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, const T& value);
template<class InputIterator, class Predicate>
constexpr typename iterator_traits<InputIterator>::difference_type
count_if(InputIterator first, InputIterator last, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
typename iterator_traits<ForwardIterator>::difference_type
count_if(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
constexpr iter_difference_t<I>
ranges::count(I first, S last, const T& value, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr range_difference_t<R>
ranges::count(R&& r, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
iter_difference_t<I>
ranges::count(Ep&& exec, I first, S last, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to,
projected<iterator_t<R>, Proj>, const T*>
range_difference_t<R> ranges::count(Ep&& exec, R&& r, const T& value, Proj proj = {});
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr iter_difference_t<I>
ranges::count_if(I first, S last, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr range_difference_t<R>
ranges::count_if(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
iter_difference_t<I>
ranges::count_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
range_difference_t<R>
ranges::count_if(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5436)
Let E be:
- [(1.1)](#1.1)
*i == value for the overloads
with no parameter pred or proj;
- [(1.2)](#1.2)
pred(*i) != false for the overloads
with a parameter pred but no parameter proj;
- [(1.3)](#1.3)
invoke(proj, *i) == value for the overloads
with a parameter proj but no parameter pred;
- [(1.4)](#1.4)
bool(invoke(pred, invoke(proj, *i))) for the overloads
with both parameters proj and pred[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5453)
*Effects*: Returns the number of iterators i in the range [first, last)
for which E holds[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5458)
*Complexity*: Exactly last - first applications
of the corresponding predicate and any projection[.](#3.sentence-1)

102
cppdraft/alg/ends/with.md Normal file
View File

@@ -0,0 +1,102 @@
[alg.ends.with]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.ends.with)
### 26.6.17 Ends with [alg.ends.with]
[🔗](#lib:ends_with)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires ([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I1> || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<S1, I1>) &&
([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I2> || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<S2, I2>) &&
[indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr bool ranges::ends_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6091)
Let N1 be last1 - first1 andN2 be last2 - first2[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6095)
*Returns*: false if N1 < N2, otherwise:ranges::equal(std::move(first1) + (N1 - N2), last1, std::move(first2), last2,
pred, proj1, proj2)
[🔗](#itemdecl:2)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
bool ranges::ends_with(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6114)
Let N1 be last1 - first1 andN2 be last2 - first2[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6118)
*Returns*: false if N1 < N2, otherwise:ranges::equal(std::forward<Ep>(exec), std::move(first1) + (N1 - N2), last1,
std::move(first2), last2, pred, proj1, proj2)
[🔗](#itemdecl:3)
`template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity,
class Proj2 = identity>
requires ([forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]")<R1> || [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]")<R1>) &&
([forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]")<R2> || [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]")<R2>) &&
[indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr bool ranges::ends_with(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6138)
Let N1 be ranges::distance(r1) andN2 be ranges::distance(r2)[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6142)
*Returns*: false if N1 < N2, otherwise:ranges::equal(views::drop(ranges::ref_view(r1), N1 - static_cast<decltype(N1)>(N2)),
r2, pred, proj1, proj2)
[🔗](#itemdecl:4)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2, class Pred = ranges::equal_to,
class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
bool ranges::ends_with(Ep&& exec, R1&& r1, R2&& r2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6161)
Let N1 be ranges::distance(r1) andN2 be ranges::distance(r2)[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6165)
*Returns*: false if N1 < N2, otherwise:ranges::equal(std::forward<Ep>(exec),
views::drop(ranges::ref_view(r1), N1 - static_cast<decltype(N1)>(N2)),
r2, pred, proj1, proj2)

130
cppdraft/alg/equal.md Normal file
View File

@@ -0,0 +1,130 @@
[alg.equal]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.equal)
### 26.6.13 Equal [alg.equal]
[🔗](#lib:equal)
`template<class InputIterator1, class InputIterator2>
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
bool equal(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
template<class InputIterator1, class InputIterator2,
class BinaryPredicate>
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
bool equal(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, BinaryPredicate pred);
template<class InputIterator1, class InputIterator2>
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
bool equal(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class InputIterator1, class InputIterator2,
class BinaryPredicate>
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
bool equal(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, class Pred = ranges::equal_to,
class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
bool ranges::equal(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
bool ranges::equal(Ep&& exec, R1&& r1, R2&& r2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5645)
Let:
- [(1.1)](#1.1)
last2 be first2 + (last1 - first1) for the overloads in namespace std with no parameter last2;
- [(1.2)](#1.2)
pred be equal_to{} for the overloads with no parameter pred;
- [(1.3)](#1.3)
E be:
* [(1.3.1)](#1.3.1)
pred(*i, *(first2 + (i - first1))) for the overloads with no parameter proj1;
* [(1.3.2)](#1.3.2)
invoke(pred, invoke(proj1, *i), invoke(proj2, *(first2 + (i - first1)))) for the overloads with parameter proj1[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5667)
*Returns*: If last1 - first1 != last2 - first2, return false[.](#2.sentence-1)
Otherwise return true if E holds for every iterator i in the range [first1, last1)[.](#2.sentence-2)
Otherwise, returns false[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5674)
*Complexity*: If
- [(3.1)](#3.1)
the types of first1, last1, first2, and last2 meet the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7Random access iterators[random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators"))
and last1 - first1 != last2 - first2 for the overloads in namespace std;
- [(3.2)](#3.2)
the types of first1, last1, first2, and last2 pairwise model [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]") ([[iterator.concept.sizedsentinel]](iterator.concept.sizedsentinel "24.3.4.8Concept sized_­sentinel_­for"))
and last1 - first1 != last2 - first2 for the first and third overloads in namespace ranges, or
- [(3.3)](#3.3)
R1 and R2 each model [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]") and ranges::distance(r1) != ranges::distance(r2) for the second and fourth overloads in namespace ranges,
then no applications of the corresponding predicate and each projection;
otherwise, at most min(last1 - first1, last2 - first2) applications of the corresponding predicate and any projections[.](#3.sentence-1)

78
cppdraft/alg/fill.md Normal file
View File

@@ -0,0 +1,78 @@
[alg.fill]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.fill)
### 26.7.6 Fill [alg.fill]
[🔗](#lib:fill)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value);
template<class ExecutionPolicy, class ForwardIterator,
class T = iterator_traits<ForwardIterator>::value_type>
void fill(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, const T& value);
template<class OutputIterator, class Size, class T = iterator_traits<OutputIterator>::value_type>
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
template<class ExecutionPolicy, class ForwardIterator, class Size,
class T = iterator_traits<ForwardIterator>::value_type>
ForwardIterator fill_n(ExecutionPolicy&& exec,
ForwardIterator first, Size n, const T& value);
template<class O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S, class T = iter_value_t<O>>
requires [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T&>
constexpr O ranges::fill(O first, S last, const T& value);
template<class R, class T = range_value_t<R>>
requires [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<R, const T&>
constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value);
template<class O, class T = iter_value_t<O>>
requires [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T&>
constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> S,
class T = iter_value_t<O>>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, const T&>
O ranges::fill(Ep&& exec, O first, S last, const T& value);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class T = range_value_t<R>>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<R>, const T&>
borrowed_iterator_t<R> fill(Ep&& exec, R&& r, const T& value);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, class T = iter_value_t<O>>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, const T&>
O ranges::fill_n(Ep&& exec, O first, iter_difference_t<O> n, const T& value);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7432)
Let N be max(0, n) for the fill_n algorithms, andlast - first for the fill algorithms[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7436)
*Mandates*: The expression value is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to the output iterator[.](#2.sentence-1)
The type Size is convertible
to an integral type ([[conv.integral]](conv.integral "7.3.9Integral conversions"), [[class.conv]](class.conv "11.4.8Conversions"))[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7443)
*Effects*: Assigns value through all the iterators in the range [first, first + N)[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7448)
*Returns*: first + N[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7452)
*Complexity*: Exactly N assignments[.](#5.sentence-1)

128
cppdraft/alg/find.md Normal file
View File

@@ -0,0 +1,128 @@
[alg.find]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.find)
### 26.6.6 Find [alg.find]
[🔗](#lib:find)
`template<class InputIterator, class T = iterator_traits<InputIterator>::value_type>
constexpr InputIterator find(InputIterator first, InputIterator last,
const T& value);
template<class ExecutionPolicy, class ForwardIterator,
class T = iterator_traits<ForwardIterator>::value_type>
ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
const T& value);
template<class InputIterator, class Predicate>
constexpr InputIterator find_if(InputIterator first, InputIterator last,
Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
Predicate pred);
template<class InputIterator, class Predicate>
constexpr InputIterator find_if_not(InputIterator first, InputIterator last,
Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
ForwardIterator find_if_not(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
constexpr I ranges::find(I first, S last, const T& value, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr borrowed_iterator_t<R>
ranges::find(R&& r, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
I ranges::find(Ep&& exec, I first, S last, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to,
projected<iterator_t<R>, Proj>, const T*>
borrowed_iterator_t<R> ranges::find(Ep&& exec, R&& r, const T& value, Proj proj = {});
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr I ranges::find_if(I first, S last, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_iterator_t<R>
ranges::find_if(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
I ranges::find_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
borrowed_iterator_t<R> ranges::find_if(Ep&& exec, R&& r, Pred pred, Proj proj = {});
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr I ranges::find_if_not(I first, S last, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_iterator_t<R>
ranges::find_if_not(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
I ranges::find_if_not(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
borrowed_iterator_t<R> ranges::find_if_not(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5017)
Let E be:
- [(1.1)](#1.1)
*i == value for find;
- [(1.2)](#1.2)
pred(*i) != false for find_if;
- [(1.3)](#1.3)
pred(*i) == false for find_if_not;
- [(1.4)](#1.4)
bool(invoke(proj, *i) == value) for ranges::find;
- [(1.5)](#1.5)
bool(invoke(pred, invoke(proj, *i))) for ranges::find_if;
- [(1.6)](#1.6)
bool(!invoke(pred, invoke(proj, *i))) for ranges::find_if_not[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5028)
*Returns*: The first iterator i in the range [first, last)
for which E is true[.](#2.sentence-1)
Returns last if no such iterator is found[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5034)
*Complexity*: At most last - first applications
of the corresponding predicate and any projection[.](#3.sentence-1)

112
cppdraft/alg/find/end.md Normal file
View File

@@ -0,0 +1,112 @@
[alg.find.end]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.find.end)
### 26.6.8 Find end [alg.find.end]
[🔗](#lib:find_end)
`template<class ForwardIterator1, class ForwardIterator2>
constexpr ForwardIterator1
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator1
find_end(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
constexpr ForwardIterator1
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
ForwardIterator1
find_end(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr subrange<I1>
ranges::find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr borrowed_subrange_t<R1>
ranges::find_end(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
subrange<I1>
ranges::find_end(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
borrowed_subrange_t<R1>
ranges::find_end(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5176)
Let:
- [(1.1)](#1.1)
pred be equal_to{} for the overloads with no parameter pred;
- [(1.2)](#1.2)
E be:
* [(1.2.1)](#1.2.1)
pred(*(i + n), *(first2 + n)) for the overloads in namespace std;
* [(1.2.2)](#1.2.2)
invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n))) for the overloads in namespace ranges;
- [(1.3)](#1.3)
i be last1 if [first2, last2) is empty,
or if (last2 - first2) > (last1 - first1) is true,
or if there is no iterator
in the range [first1, last1 - (last2 - first2))
such that for every non-negative integer n < (last2 - first2), E is true[.](#1.sentence-1)
Otherwise i is the last such iterator
in [first1, last1 - (last2 - first2))[.](#1.3.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5203)
*Returns*:
- [(2.1)](#2.1)
i for the overloads in namespace std[.](#2.1.sentence-1)
- [(2.2)](#2.2)
{i, i + (i == last1 ? 0 : last2 - first2)} for the overloads in namespace ranges[.](#2.2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5211)
*Complexity*: At most(last2 - first2) * (last1 - first1 - (last2 - first2) + 1) applications of the corresponding predicate and any projections[.](#3.sentence-1)

View File

@@ -0,0 +1,102 @@
[alg.find.first.of]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.find.first.of)
### 26.6.9 Find first [alg.find.first.of]
[🔗](#lib:find_first_of)
`template<class InputIterator, class ForwardIterator>
constexpr InputIterator
find_first_of(InputIterator first1, InputIterator last1,
ForwardIterator first2, ForwardIterator last2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator1
find_first_of(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class InputIterator, class ForwardIterator,
class BinaryPredicate>
constexpr InputIterator
find_first_of(InputIterator first1, InputIterator last1,
ForwardIterator first2, ForwardIterator last2,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
ForwardIterator1
find_first_of(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr borrowed_iterator_t<R1>
ranges::find_first_of(R1&& r1, R2&& r2,
Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
I1 ranges::find_first_of(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
borrowed_iterator_t<R1>
ranges::find_first_of(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5275)
Let E be:
- [(1.1)](#1.1)
*i == *j for the overloads with no parameter pred;
- [(1.2)](#1.2)
pred(*i, *j) != false for the overloads with a parameter pred and no parameter proj1;
- [(1.3)](#1.3)
bool(invoke(pred, invoke(proj1, *i), invoke(proj2, *j))) for the overloads with parameters pred and proj1[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5283)
*Effects*: Finds an element that matches one of a set of values[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5287)
*Returns*: The first iterator i in the range [first1, last1)
such that for some iterator j in the range [first2, last2)E holds[.](#3.sentence-1)
Returns last1 if [first2, last2) is empty or
if no such iterator is found[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5296)
*Complexity*: At most (last1 - first1) * (last2 - first2) applications
of the corresponding predicate and any projections[.](#4.sentence-1)

93
cppdraft/alg/find/last.md Normal file
View File

@@ -0,0 +1,93 @@
[alg.find.last]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.find.last)
### 26.6.7 Find last [alg.find.last]
[🔗](#lib:find_last)
`template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
constexpr subrange<I> ranges::find_last(I first, S last, const T& value, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr borrowed_subrange_t<R> ranges::find_last(R&& r, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
subrange<I> ranges::find_last(Ep&& exec, I first, S last, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
borrowed_subrange_t<R> ranges::find_last(Ep&& exec, R&& r, const T& value, Proj proj = {});
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr subrange<I> ranges::find_last_if(I first, S last, Pred pred, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> ranges::find_last_if(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
subrange<I> ranges::find_last_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R,
class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
borrowed_subrange_t<R> ranges::find_last_if(Ep&& exec, R&& r, Pred pred, Proj proj = {});
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr subrange<I> ranges::find_last_if_not(I first, S last, Pred pred, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> ranges::find_last_if_not(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
subrange<I> ranges::find_last_if_not(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
borrowed_subrange_t<R> ranges::find_last_if_not(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5095)
Let E be:
- [(1.1)](#1.1)
bool(invoke(proj, *i) == value) for ranges::find_last;
- [(1.2)](#1.2)
bool(invoke(pred, invoke(proj, *i))) for ranges::find_last_if;
- [(1.3)](#1.3)
bool(!invoke(pred, invoke(proj, *i))) for ranges::find_last_if_not[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5106)
*Returns*: Let i be the last iterator in the range [first, last)
for which E is true[.](#2.sentence-1)
Returns {i, last}, or{last, last} if no such iterator is found[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5113)
*Complexity*: At most last - first applications of
the corresponding predicate and projection[.](#3.sentence-1)

143
cppdraft/alg/fold.md Normal file
View File

@@ -0,0 +1,143 @@
[alg.fold]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.fold)
### 26.6.18 Fold [alg.fold]
[🔗](#lib:fold_left)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>,
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, I> F>
constexpr auto ranges::fold_left(I first, S last, T init, F f);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class T = range_value_t<R>,
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, iterator_t<R>> F>
constexpr auto ranges::fold_left(R&& r, T init, F f);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6188)
*Returns*: ranges::fold_left_with_iter(std::move(first), last, std::move(init), f).value
[🔗](#lib:fold_left_first)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S,
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<iter_value_t<I>, I> F>
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<I>, iter_reference_t<I>>
constexpr auto ranges::fold_left_first(I first, S last, F f);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<range_value_t<R>, iterator_t<R>> F>
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<range_value_t<R>, range_reference_t<R>>
constexpr auto ranges::fold_left_first(R&& r, F f);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6207)
*Returns*: ranges::fold_left_first_with_iter(std::move(first), last, f).value
[🔗](#lib:fold_right)
`template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>,
[indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, I> F>
constexpr auto ranges::fold_right(I first, S last, T init, F f);
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, class T = range_value_t<R>,
[indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, iterator_t<R>> F>
constexpr auto ranges::fold_right(R&& r, T init, F f);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6225)
*Effects*: Equivalent to:using U = decay_t<invoke_result_t<F&, iter_reference_t<I>, T>>;if (first == last)return U(std::move(init));
I tail = ranges::next(first, last);
U accum = invoke(f, *--tail, std::move(init));while (first != tail) accum = invoke(f, *--tail, std::move(accum));return accum;
[🔗](#lib:fold_right_last)
`template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S,
[indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<iter_value_t<I>, I> F>
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<I>, iter_reference_t<I>>
constexpr auto ranges::fold_right_last(I first, S last, F f);
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R,
[indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<range_value_t<R>, iterator_t<R>> F>
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<range_value_t<R>, range_reference_t<R>>
constexpr auto ranges::fold_right_last(R&& r, F f);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6253)
Let U bedecltype(ranges::fold_right(first, last, iter_value_t<I>(*first), f))[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6257)
*Effects*: Equivalent to:if (first == last)return optional<U>();
I tail = ranges::prev(ranges::next(first, std::move(last)));return optional<U>(in_place,
ranges::fold_right(std::move(first), tail, iter_value_t<I>(*tail), std::move(f)));
[🔗](#lib:fold_left_with_iter)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>,
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, I> F>
constexpr see below ranges::fold_left_with_iter(I first, S last, T init, F f);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class T = range_value_t<R>,
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, iterator_t<R>> F>
constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6280)
Let U be decay_t<invoke_result_t<F&, T, iter_reference_t<I>>>[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6283)
*Effects*: Equivalent to:if (first == last)return {std::move(first), U(std::move(init))};
U accum = invoke(f, std::move(init), *first);for (++first; first != last; ++first) accum = invoke(f, std::move(accum), *first);return {std::move(first), std::move(accum)};
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6295)
*Remarks*: The return type isfold_left_with_iter_result<I, U> for the first overload andfold_left_with_iter_result<borrowed_iterator_t<R>, U> for the second overload[.](#8.sentence-1)
[🔗](#lib:fold_left_first_with_iter)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S,
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<iter_value_t<I>, I> F>
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<I>, iter_reference_t<I>>
constexpr see below ranges::fold_left_first_with_iter(I first, S last, F f);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<range_value_t<R>, iterator_t<R>> F>
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<range_value_t<R>, range_reference_t<R>>
constexpr see below ranges::fold_left_first_with_iter(R&& r, F f);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6315)
Let U bedecltype(ranges::fold_left(std::move(first), last, iter_value_t<I>(*first), f))
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6321)
*Effects*: Equivalent to:if (first == last)return {std::move(first), optional<U>()};
optional<U> init(in_place, *first);for (++first; first != last; ++first)*init = invoke(f, std::move(*init), *first);return {std::move(first), std::move(init)};
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6333)
*Remarks*: The return type isfold_left_first_with_iter_result<I, optional<U>> for the first overload andfold_left_first_with_iter_result<borrowed_iterator_t<R>, optional<U>> for the second overload[.](#11.sentence-1)

435
cppdraft/alg/foreach.md Normal file
View File

@@ -0,0 +1,435 @@
[alg.foreach]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.foreach)
### 26.6.5 For each [alg.foreach]
[🔗](#lib:for_each)
`template<class InputIterator, class Function>
constexpr Function for_each(InputIterator first, InputIterator last, Function f);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4616)
*Preconditions*: Function meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements"))[.](#1.sentence-1)
[*Note [1](#note-1)*:
Function need not meet the requirements of[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))[.](#1.sentence-2)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4625)
*Effects*: Applies f to the result of dereferencing
every iterator in the range [first, last),
starting from first and proceeding to last - 1[.](#2.sentence-1)
[*Note [2](#note-2)*:
If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4635)
*Returns*: f[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4639)
*Complexity*: Applies f exactly last - first times[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4643)
*Remarks*: If f returns a result, the result is ignored[.](#5.sentence-1)
[🔗](#lib:for_each_)
`template<class ExecutionPolicy, class ForwardIterator, class Function>
void for_each(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Function f);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4657)
*Preconditions*: Function meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4661)
*Effects*: Applies f to the result of dereferencing
every iterator in the range [first, last)[.](#7.sentence-1)
[*Note [3](#note-3)*:
If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#7.sentence-2)
— *end note*]
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4670)
*Complexity*: Applies f exactly last - first times[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4674)
*Remarks*: If f returns a result, the result is ignored[.](#9.sentence-1)
Implementations do not have
the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#9.sentence-2)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4681)
[*Note [4](#note-4)*:
Does not return a copy of its Function parameter,
since parallelization often does not permit efficient state accumulation[.](#10.sentence-1)
— *end note*]
[🔗](#lib:for_each__)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Fun>
constexpr ranges::for_each_result<I, Fun>
ranges::for_each(I first, S last, Fun f, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Fun>
constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
ranges::for_each(R&& r, Fun f, Proj proj = {});
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4701)
*Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, last),
starting from first and proceeding to last - 1[.](#11.sentence-1)
[*Note [5](#note-5)*:
If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#11.sentence-2)
— *end note*]
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4711)
*Returns*: {last, std::move(f)}[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4715)
*Complexity*: Applies f and proj exactly last - first times[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4719)
*Remarks*: If f returns a result, the result is ignored[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4723)
[*Note [6](#note-6)*:
The overloads in namespace ranges requireFun to model [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]")[.](#15.sentence-1)
— *end note*]
[🔗](#itemdecl:4)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Fun>
I ranges::for_each(Ep&& exec, I first, S last, Fun f, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Fun>
borrowed_iterator_t<R>
ranges::for_each(Ep&& exec, R&& r, Fun f, Proj proj = {});
`
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4742)
*Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, last)[.](#16.sentence-1)
[*Note [7](#note-7)*:
If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#16.sentence-2)
— *end note*]
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4752)
*Returns*: last[.](#17.sentence-1)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4756)
*Complexity*: Applies f and proj exactly last - first times[.](#18.sentence-1)
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4760)
*Remarks*:
- [(19.1)](#19.1)
If f returns a result, the result is ignored[.](#19.1.sentence-1)
- [(19.2)](#19.2)
Implementations do not have the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#19.2.sentence-1)
- [(19.3)](#19.3)
f may modify objects via its arguments ([[algorithms.parallel.user]](algorithms.parallel.user "26.3.2Requirements on user-provided function objects"))[.](#19.3.sentence-1)
[*Note [8](#note-8)*:
Does not return a copy of its Fun parameter,
since parallelization often does not permit
efficient state accumulation[.](#19.sentence-2)
— *end note*]
[🔗](#lib:for_each_n)
`template<class InputIterator, class Size, class Function>
constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
`
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4785)
*Mandates*: The type Size is convertible
to an integral type ([[conv.integral]](conv.integral "7.3.9Integral conversions"), [[class.conv]](class.conv "11.4.8Conversions"))[.](#20.sentence-1)
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4790)
*Preconditions*: n >= 0 is true[.](#21.sentence-1)
Function meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#21.sentence-2)
[*Note [9](#note-9)*:
Function need not meet
the requirements of [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]")[.](#21.sentence-3)
— *end note*]
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4799)
*Effects*: Applies f to the result of dereferencing
every iterator in the range [first, first + n) in order[.](#22.sentence-1)
[*Note [10](#note-10)*:
If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#22.sentence-2)
— *end note*]
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4808)
*Returns*: first + n[.](#23.sentence-1)
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4812)
*Remarks*: If f returns a result, the result is ignored[.](#24.sentence-1)
[🔗](#lib:for_each_n_)
`template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
Function f);
`
[25](#25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4825)
*Mandates*: The type Size is convertible
to an integral type ([[conv.integral]](conv.integral "7.3.9Integral conversions"), [[class.conv]](class.conv "11.4.8Conversions"))[.](#25.sentence-1)
[26](#26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4830)
*Preconditions*: n >= 0 is true[.](#26.sentence-1)
Function meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#26.sentence-2)
[27](#27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4835)
*Effects*: Applies f to the result of dereferencing
every iterator in the range [first, first + n)[.](#27.sentence-1)
[*Note [11](#note-11)*:
If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#27.sentence-2)
— *end note*]
[28](#28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4844)
*Returns*: first + n[.](#28.sentence-1)
[29](#29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4848)
*Remarks*: If f returns a result, the result is ignored[.](#29.sentence-1)
Implementations do not have
the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#29.sentence-2)
[🔗](#lib:for_each_n__)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, class Proj = identity,
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Fun>
constexpr ranges::for_each_n_result<I, Fun>
ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {});
`
[30](#30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4865)
*Preconditions*: n >= 0 is true[.](#30.sentence-1)
[31](#31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4869)
*Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range
[first, first + n) in order[.](#31.sentence-1)
[*Note [12](#note-12)*:
If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#31.sentence-2)
— *end note*]
[32](#32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4879)
*Returns*: {first + n, std::move(f)}[.](#32.sentence-1)
[33](#33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4883)
*Remarks*: If f returns a result, the result is ignored[.](#33.sentence-1)
[34](#34)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4887)
[*Note [13](#note-13)*:
The overload in namespace ranges requires Fun to model [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]")[.](#34.sentence-1)
— *end note*]
[🔗](#itemdecl:8)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, class Proj = identity,
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Fun>
I ranges::for_each_n(Ep&& exec, I first, iter_difference_t<I> n, Fun f, Proj proj = {});
`
[35](#35)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4901)
*Preconditions*: n >= 0 is true[.](#35.sentence-1)
[36](#36)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4905)
*Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, first + n)[.](#36.sentence-1)
[*Note [14](#note-14)*:
If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#36.sentence-2)
— *end note*]
[37](#37)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4915)
*Returns*: first + n[.](#37.sentence-1)
[38](#38)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4919)
*Remarks*:
- [(38.1)](#38.1)
If f returns a result, the result is ignored[.](#38.1.sentence-1)
- [(38.2)](#38.2)
Implementations do not have the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#38.2.sentence-1)
- [(38.3)](#38.3)
f may modify objects via its arguments ([[algorithms.parallel.user]](algorithms.parallel.user "26.3.2Requirements on user-provided function objects"))[.](#38.3.sentence-1)
[*Note [15](#note-15)*:
Does not return a copy of its Fun parameter,
since parallelization often does not permit
efficient state accumulation[.](#38.sentence-2)
— *end note*]

50
cppdraft/alg/func/obj.md Normal file
View File

@@ -0,0 +1,50 @@
[alg.func.obj]
# 16 Library introduction [[library]](./#library)
## 16.3 Method of description [[description]](description#alg.func.obj)
### 16.3.3 Other conventions [[conventions]](conventions#alg.func.obj)
#### 16.3.3.4 Algorithm function objects [alg.func.obj]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L895)
An [*algorithm function object*](#def:algorithm_function_object "16.3.3.4Algorithm function objects[alg.func.obj]") is
a customization point object ([[customization.point.object]](customization.point.object "16.3.3.3.5Customization Point Object types"))
that is specified as one or more overloaded function templates[.](#1.sentence-1)
The name of these function templates designates
the corresponding algorithm function object[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L902)
For an algorithm function object o,
let S be the corresponding set of function templates[.](#2.sentence-1)
Then for any sequence of arguments args …,o(args …) is expression-equivalent tos(args …),
where the result of name lookup for s is the overload set S[.](#2.sentence-2)
[*Note [1](#note-1)*:
Algorithm function objects are not found by
argument-dependent name lookup ([[basic.lookup.argdep]](basic.lookup.argdep "6.5.4Argument-dependent name lookup"))[.](#2.sentence-3)
When found by unqualified name lookup ([[basic.lookup.unqual]](basic.lookup.unqual "6.5.3Unqualified name lookup"))
for the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1General[expr.post.general]") in a function call ([[expr.call]](expr.call "7.6.1.3Function call")),
they inhibit argument-dependent name lookup[.](#2.sentence-4)
[*Example [1](#example-1)*: void foo() {using namespace std::ranges;
std::vector<int> vec{1,2,3};
find(begin(vec), end(vec), 2); // #1}
The function call expression at #1 invokes std::ranges::find,
not std::find[.](#2.sentence-5)
— *end example*]
— *end note*]

83
cppdraft/alg/generate.md Normal file
View File

@@ -0,0 +1,83 @@
[alg.generate]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.generate)
### 26.7.7 Generate [alg.generate]
[🔗](#lib:generate)
`template<class ForwardIterator, class Generator>
constexpr void generate(ForwardIterator first, ForwardIterator last,
Generator gen);
template<class ExecutionPolicy, class ForwardIterator, class Generator>
void generate(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Generator gen);
template<class OutputIterator, class Size, class Generator>
constexpr OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
ForwardIterator generate_n(ExecutionPolicy&& exec,
ForwardIterator first, Size n, Generator gen);
template<[input_or_output_iterator](iterator.concept.iterator#concept:input_or_output_iterator "24.3.4.6Concept input_­or_­output_­iterator[iterator.concept.iterator]") O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, invoke_result_t<F&>>
constexpr O ranges::generate(O first, S last, F gen);
template<class R, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<F&> && [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<R, invoke_result_t<F&>>
constexpr borrowed_iterator_t<R> ranges::generate(R&& r, F gen);
template<[input_or_output_iterator](iterator.concept.iterator#concept:input_or_output_iterator "24.3.4.6Concept input_­or_­output_­iterator[iterator.concept.iterator]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, invoke_result_t<F&>>
constexpr O ranges::generate_n(O first, iter_difference_t<O> n, F gen);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> S,
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, invoke_result_t<F&>>
O ranges::generate(Ep&& exec, O first, S last, F gen);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<R>, invoke_result_t<F&>>
borrowed_iterator_t<R> ranges::generate(Ep&& exec, R&& r, F gen);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, invoke_result_t<F&>>
O ranges::generate_n(Ep&& exec, O first, iter_difference_t<O> n, F gen);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7499)
Let N be max(0, n) for the generate_n algorithms, andlast - first for the generate algorithms[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7503)
*Mandates*: Size is convertible
to an integral type ([[conv.integral]](conv.integral "7.3.9Integral conversions"), [[class.conv]](class.conv "11.4.8Conversions"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7508)
*Effects*: Assigns the result of successive evaluations of gen() through each iterator in the range [first, first + N)[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7513)
*Returns*: first + N[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7517)
*Complexity*: Exactly N evaluations of gen() and assignments[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7521)
*Remarks*: gen may modify objects via its arguments
for parallel algorithm overloads ([[algorithms.parallel.user]](algorithms.parallel.user "26.3.2Requirements on user-provided function objects"))[.](#6.sentence-1)

View File

@@ -0,0 +1,417 @@
[alg.heap.operations]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.heap.operations)
### 26.8.8 Heap operations [alg.heap.operations]
#### [26.8.8.1](#general) General [[alg.heap.operations.general]](alg.heap.operations.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10877)
A random access range [a, b) is a[*heap with respect to comp and proj*](#def:heap_with_respect_to_comp_and_proj "26.8.8.1General[alg.heap.operations.general]") for a comparator and projection comp and proj if its elements are organized such that:
- [(1.1)](#general-1.1)
With N = b - a, for all i, 0<i<N, bool(invoke(comp, invoke(proj, a[⌊ˆ’12⌋]), invoke(proj, a[i]))) is false[.](#general-1.1.sentence-1)
- [(1.2)](#general-1.2)
*a may be removed by pop_heap, or
a new element added by push_heap,
in O(logN) time[.](#general-1.2.sentence-1)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10894)
These properties make heaps useful as priority queues[.](#general-2.sentence-1)
[3](#general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10897)
make_heap converts a range into a heap andsort_heap turns a heap into a sorted sequence[.](#general-3.sentence-1)
#### [26.8.8.2](#push.heap) push_heap [[push.heap]](push.heap)
[🔗](#lib:push_heap)
`template<class RandomAccessIterator>
constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I
ranges::push_heap(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::push_heap(R&& r, Comp comp = {}, Proj proj = {});
`
[1](#push.heap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10924)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#push.heap-1.sentence-1)
[2](#push.heap-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10929)
*Preconditions*: The range [first, last - 1)
is a valid heap with respect to comp and proj[.](#push.heap-2.sentence-1)
For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and
the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements"))[.](#push.heap-2.sentence-2)
[3](#push.heap-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10940)
*Effects*: Places the value in the location last - 1 into the resulting heap [first, last)[.](#push.heap-3.sentence-1)
[4](#push.heap-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10945)
*Returns*: last for the overloads in namespace ranges[.](#push.heap-4.sentence-1)
[5](#push.heap-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10949)
*Complexity*: At most log(last - first) comparisons and twice as many projections[.](#push.heap-5.sentence-1)
#### [26.8.8.3](#pop.heap) pop_heap [[pop.heap]](pop.heap)
[🔗](#lib:pop_heap)
`template<class RandomAccessIterator>
constexpr void pop_heap(RandomAccessIterator first, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void pop_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I
ranges::pop_heap(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::pop_heap(R&& r, Comp comp = {}, Proj proj = {});
`
[1](#pop.heap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10977)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#pop.heap-1.sentence-1)
[2](#pop.heap-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10982)
*Preconditions*: The range [first, last)
is a valid non-empty heap with respect to comp and proj[.](#pop.heap-2.sentence-1)
For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#pop.heap-2.sentence-2)
[3](#pop.heap-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10993)
*Effects*: Swaps the value in the location first with the value in the locationlast - 1 and makes
[first, last - 1)
into a heap with respect to comp and proj[.](#pop.heap-3.sentence-1)
[4](#pop.heap-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11002)
*Returns*: last for the overloads in namespace ranges[.](#pop.heap-4.sentence-1)
[5](#pop.heap-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11006)
*Complexity*: At most 2log(last - first) comparisons and
twice as many projections[.](#pop.heap-5.sentence-1)
#### [26.8.8.4](#make.heap) make_heap [[make.heap]](make.heap)
[🔗](#lib:make_heap)
`template<class RandomAccessIterator>
constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I
ranges::make_heap(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::make_heap(R&& r, Comp comp = {}, Proj proj = {});
`
[1](#make.heap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11035)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#make.heap-1.sentence-1)
[2](#make.heap-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11040)
*Preconditions*: For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#make.heap-2.sentence-1)
[3](#make.heap-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11049)
*Effects*: Constructs a heap with respect to comp and proj out of the range [first, last)[.](#make.heap-3.sentence-1)
[4](#make.heap-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11054)
*Returns*: last for the overloads in namespace ranges[.](#make.heap-4.sentence-1)
[5](#make.heap-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11058)
*Complexity*: At most 3(last - first) comparisons and twice as many projections[.](#make.heap-5.sentence-1)
#### [26.8.8.5](#sort.heap) sort_heap [[sort.heap]](sort.heap)
[🔗](#lib:sort_heap)
`template<class RandomAccessIterator>
constexpr void sort_heap(RandomAccessIterator first, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I
ranges::sort_heap(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::sort_heap(R&& r, Comp comp = {}, Proj proj = {});
`
[1](#sort.heap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11086)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#sort.heap-1.sentence-1)
[2](#sort.heap-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11091)
*Preconditions*: The range [first, last) is
a valid heap with respect to comp and proj[.](#sort.heap-2.sentence-1)
For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#sort.heap-2.sentence-2)
[3](#sort.heap-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11102)
*Effects*: Sorts elements in the heap [first, last)
with respect to comp and proj[.](#sort.heap-3.sentence-1)
[4](#sort.heap-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11107)
*Returns*: last for the overloads in namespace ranges[.](#sort.heap-4.sentence-1)
[5](#sort.heap-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11111)
*Complexity*: At most 2NlogN comparisons, where N=last - first, and
twice as many projections[.](#sort.heap-5.sentence-1)
#### [26.8.8.6](#is.heap) is_heap [[is.heap]](is.heap)
[🔗](#lib:is_heap)
`template<class RandomAccessIterator>
constexpr bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
`
[1](#is.heap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11126)
*Effects*: Equivalent to: return is_heap_until(first, last) == last;
[🔗](#lib:is_heap_)
`template<class ExecutionPolicy, class RandomAccessIterator>
bool is_heap(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last);
`
[2](#is.heap-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11139)
*Effects*: Equivalent to:return is_heap_until(std::forward<ExecutionPolicy>(exec), first, last) == last;
[🔗](#lib:is_heap__)
`template<class RandomAccessIterator, class Compare>
constexpr bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
`
[3](#is.heap-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11155)
*Effects*: Equivalent to: return is_heap_until(first, last, comp) == last;
[🔗](#lib:is_heap___)
`template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
bool is_heap(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
`
[4](#is.heap-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11169)
*Effects*: Equivalent to:return is_heap_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last;
[🔗](#lib:is_heap____)
`template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
constexpr bool ranges::is_heap(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
constexpr bool ranges::is_heap(R&& r, Comp comp = {}, Proj proj = {});
`
[5](#is.heap-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11188)
*Effects*: Equivalent to:return ranges::is_heap_until(first, last, comp, proj) == last;
[🔗](#is.heap-itemdecl:6)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
bool ranges::is_heap(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
bool ranges::is_heap(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[6](#is.heap-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11205)
*Effects*: Equivalent to:return ranges::is_heap_until(std::forward<Ep>(exec), first, last, comp, proj) == last;
[🔗](#lib:is_heap_until)
`template<class RandomAccessIterator>
constexpr RandomAccessIterator
is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
template<class ExecutionPolicy, class RandomAccessIterator>
RandomAccessIterator
is_heap_until(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr RandomAccessIterator
is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
RandomAccessIterator
is_heap_until(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
constexpr I ranges::is_heap_until(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
constexpr borrowed_iterator_t<R>
ranges::is_heap_until(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
I ranges::is_heap_until(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
borrowed_iterator_t<R>
ranges::is_heap_until(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[7](#is.heap-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11252)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#is.heap-7.sentence-1)
[8](#is.heap-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11257)
*Returns*: The last iterator i in [first, last]
for which the range [first, i)
is a heap with respect to comp and proj[.](#is.heap-8.sentence-1)
[9](#is.heap-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11263)
*Complexity*: Linear[.](#is.heap-9.sentence-1)

View File

@@ -0,0 +1,37 @@
[alg.heap.operations.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.heap.operations.general)
### 26.8.8 Heap operations [[alg.heap.operations]](alg.heap.operations#general)
#### 26.8.8.1 General [alg.heap.operations.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10877)
A random access range [a, b) is a[*heap with respect to comp and proj*](#def:heap_with_respect_to_comp_and_proj "26.8.8.1General[alg.heap.operations.general]") for a comparator and projection comp and proj if its elements are organized such that:
- [(1.1)](#1.1)
With N = b - a, for all i, 0<i<N, bool(invoke(comp, invoke(proj, a[⌊ˆ’12⌋]), invoke(proj, a[i]))) is false[.](#1.1.sentence-1)
- [(1.2)](#1.2)
*a may be removed by pop_heap, or
a new element added by push_heap,
in O(logN) time[.](#1.2.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10894)
These properties make heaps useful as priority queues[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10897)
make_heap converts a range into a heap andsort_heap turns a heap into a sorted sequence[.](#3.sentence-1)

View File

@@ -0,0 +1,127 @@
[alg.is.permutation]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.is.permutation)
### 26.6.14 Is permutation [alg.is.permutation]
[🔗](#lib:is_permutation)
`template<class ForwardIterator1, class ForwardIterator2>
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
template<class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, BinaryPredicate pred);
template<class ForwardIterator1, class ForwardIterator2>
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5722)
Let last2 be first2 + (last1 - first1) for the overloads with no parameter named last2,
and let pred be equal_to{} for the overloads with no parameter pred[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5728)
*Mandates*: ForwardIterator1 and ForwardIterator2 have the same value type[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5732)
*Preconditions*: The comparison function is an equivalence relation[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5736)
*Returns*: If last1 - first1 != last2 - first2, return false[.](#4.sentence-1)
Otherwise return true if there exists a permutation of the elements
in the range [first2, last2),
beginning with ForwardIterator2 begin,
such that equal(first1, last1, begin, pred) returns true;
otherwise, returns false[.](#4.sentence-2)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5746)
*Complexity*: No applications of the corresponding predicate
if ForwardIterator1 and ForwardIterator2 meet the requirements of random access iterators andlast1 - first1 != last2 - first2[.](#5.sentence-1)
Otherwise, exactly last1 - first1 applications
of the corresponding predicate
if equal(first1, last1, first2, last2, pred) would return true;
otherwise, at worst O(N2), where N has the value last1 - first1[.](#5.sentence-2)
[🔗](#lib:is_permutation_)
`template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I2,
[sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2, class Proj1 = identity, class Proj2 = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I1, Proj1>,
projected<I2, Proj2>> Pred = ranges::equal_to>
constexpr bool ranges::is_permutation(I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R2,
class Proj1 = identity, class Proj2 = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>> Pred = ranges::equal_to>
constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5776)
*Returns*: If last1 - first1 != last2 - first2, return false[.](#6.sentence-1)
Otherwise return true if there exists a permutation of the elements
in the range [first2, last2), bounded by [pfirst, plast),
such thatranges::equal(first1, last1, pfirst, plast, pred, proj1, proj2) returns true;
otherwise, returns false[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5786)
*Complexity*: No applications of the corresponding predicate and projections if
- [(7.1)](#7.1)
for the first overload,
* [(7.1.1)](#7.1.1)
S1 and I1 model [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<S1, I1>,
* [(7.1.2)](#7.1.2)
S2 and I2 model [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<S2, I2>, and
* [(7.1.3)](#7.1.3)
last1 - first1 != last2 - first2;
- [(7.2)](#7.2)
for the second overload,R1 and R2 each model [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]"), andranges::distance(r1) != ranges::distance(r2)[.](#7.sentence-1)
Otherwise, exactly last1 - first1 applications
of the corresponding predicate and projections
if ranges::equal(first1, last1, first2, last2, pred, proj1, proj2) would return true;
otherwise, at worst O(N2), where N has the value last1 - first1[.](#7.sentence-2)

View File

@@ -0,0 +1,114 @@
[alg.lex.comparison]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.lex.comparison)
### 26.8.11 Lexicographical comparison [alg.lex.comparison]
[🔗](#lib:lexicographical_compare)
`template<class InputIterator1, class InputIterator2>
constexpr bool
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
bool
lexicographical_compare(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class InputIterator1, class InputIterator2, class Compare>
constexpr bool
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare comp);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class Compare>
bool
lexicographical_compare(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Proj1 = identity, class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I1, Proj1>,
projected<I2, Proj2>> Comp = ranges::less>
constexpr bool
ranges::lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, class Proj1 = identity,
class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
constexpr bool
ranges::lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Proj1 = identity, class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I1, Proj1>,
projected<I2, Proj2>> Comp = ranges::less>
bool ranges::lexicographical_compare(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Proj1 = identity, class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
bool ranges::lexicographical_compare(Ep&& exec, R1&& r1, R2&& r2, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11801)
*Returns*: true if and only if
the sequence of elements defined by the range [first1, last1)
is lexicographically less than
the sequence of elements defined by the range [first2, last2)[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11808)
*Complexity*: At most 2 min(last1 - first1, last2 - first2) applications
of the corresponding comparison and each projection, if any[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11813)
*Remarks*: If two sequences have the same number of elements and
their corresponding elements (if any) are equivalent,
then neither sequence is lexicographically less than the other[.](#3.sentence-1)
If one sequence is a proper prefix of the other,
then the shorter sequence is lexicographically less than the longer sequence[.](#3.sentence-2)
Otherwise, the lexicographical comparison of the sequences yields
the same result as the comparison
of the first corresponding pair of elements that are not equivalent[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11824)
[*Example [1](#example-1)*:
ranges::lexicographical_compare(I1, S1, I2, S2, Comp, Proj1, Proj2) can be implemented as:for (; first1 != last1 && first2 != last2; ++first1, (void)++first2) {if (invoke(comp, invoke(proj1, *first1), invoke(proj2, *first2))) return true; if (invoke(comp, invoke(proj2, *first2), invoke(proj1, *first1))) return false;}return first1 == last1 && first2 != last2;
— *end example*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11837)
[*Note [1](#note-1)*:
An empty sequence is lexicographically less than any non-empty sequence,
but not less than any empty sequence[.](#5.sentence-1)
— *end note*]

280
cppdraft/alg/merge.md Normal file
View File

@@ -0,0 +1,280 @@
[alg.merge]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.merge)
### 26.8.6 Merge [alg.merge]
[🔗](#lib:merge)
`template<class InputIterator1, class InputIterator2,
class OutputIterator>
constexpr OutputIterator
merge(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator>
ForwardIterator
merge(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result);
template<class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
constexpr OutputIterator
merge(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare comp);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator, class Compare>
ForwardIterator
merge(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result, Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Comp = ranges::less, class Proj1 = identity,
class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
constexpr ranges::merge_result<I1, I2, O>
ranges::merge(I1 first1, S1 last1, I2 first2, S2 last2, O result,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
constexpr ranges::merge_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
ranges::merge(R1&& r1, R2&& r2, O result,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
ranges::merge_result<I1, I2, O>
ranges::merge(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, O result, OutS result_last,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, iterator_t<OutR>, Comp, Proj1, Proj2>
ranges::merge_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, borrowed_iterator_t<OutR>>
ranges::merge(Ep&& exec, R1&& r1, R2&& r2, OutR&& result_r,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10071)
Let:
- [(1.1)](#1.1)
N be:
* [(1.1.1)](#1.1.1)
(last1 - first1) + (last2 - first2) for the overloads with no parameter result_last or result_r;
* [(1.1.2)](#1.1.2)
min((last1 - first1) + (last2 - first2), result_last - result) for the overloads with parameters result_last or result_r;
- [(1.2)](#1.2)
comp be less{}, proj1 be identity{}, and proj2 be identity{},
for the overloads with no parameters by those names;
- [(1.3)](#1.3)
E(e1, e1) be bool(invoke(comp, invoke(proj2, e2), invoke(proj1, e1)));
- [(1.4)](#1.4)
K be the smallest integer in [0, last1 - first1)
such that for the element e1 in the position first1 + K there are at least N−K elements e2 in [first2, last2) for which E(e1, e1) holds,
and be equal to last1 - first1 if no such integer exists[.](#1.sentence-1)
[*Note [1](#note-1)*:
first1 + K points to the position past the last element to be copied[.](#1.4.sentence-2)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10103)
*Preconditions*: The ranges [first1, last1) and [first2, last2)
are sorted with respect to comp and proj1 or proj2,
respectively[.](#2.sentence-1)
The resulting range does not overlap with either of the original ranges[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10110)
*Effects*: Copies the first K elements of the range [first1, last1)
and the first N−K elements of the range [first2, last2)
into the range [result, result + N)[.](#3.sentence-1)
If an element a precedes b in an input range,a is copied into the output range before b[.](#3.sentence-2)
If e1 is an element of [first1, last1) ande2 of [first2, last2),e2 is copied into the output range before e1 if and only if E(e1, e1) is true[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10122)
*Returns*:
- [(4.1)](#4.1)
result + N for the overloads in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{first1 + K, first2 + N - K, result + N} for the overloads in namespace ranges[.](#4.2.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10133)
*Complexity*:
- [(5.1)](#5.1)
For the non-parallel algorithm overloads,
at most N−1 comparisons and applications of each projection[.](#5.1.sentence-1)
- [(5.2)](#5.2)
For the parallel algorithm overloads, O(N) comparisons and applications of each projection[.](#5.2.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10144)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#6.sentence-1)
[🔗](#lib:inplace_merge)
`template<class BidirectionalIterator>
constexpr void inplace_merge(BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last);
template<class ExecutionPolicy, class BidirectionalIterator>
void inplace_merge(ExecutionPolicy&& exec,
BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last);
template<class BidirectionalIterator, class Compare>
constexpr void inplace_merge(BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last, Compare comp);
template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
void inplace_merge(ExecutionPolicy&& exec,
BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last, Compare comp);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I ranges::inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
I ranges::inplace_merge(Ep&& exec, I first, I middle, S last, Comp comp = {}, Proj proj = {});
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10182)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10187)
*Preconditions*: [first, middle) and [middle, last) are valid ranges
sorted with respect to comp and proj[.](#8.sentence-1)
For the overloads in namespace std,BidirectionalIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#8.sentence-2)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10198)
*Effects*: Merges two sorted consecutive ranges
[first, middle) and [middle, last),
putting the result of the merge into the range [first, last)[.](#9.sentence-1)
The resulting range is sorted with respect to comp and proj[.](#9.sentence-2)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10205)
*Returns*: last for the overload in namespace ranges[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10209)
*Complexity*: Let N=last - first:
- [(11.1)](#11.1)
For the non-parallel algorithm overloads, and
if enough additional memory is available, at most N−1 comparisons[.](#11.1.sentence-1)
- [(11.2)](#11.2)
Otherwise, O(NlogN) comparisons[.](#11.2.sentence-1)
In either case, twice as many projections as comparisons[.](#11.sentence-2)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10221)
*Remarks*: [Stable](algorithm.stable "16.4.6.8Requirements for stable algorithms[algorithm.stable]")[.](#12.sentence-1)
[🔗](#itemdecl:3)
`template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10234)
*Effects*: Equivalent to:return ranges::inplace_merge(ranges::begin(r), middle, ranges::end(r), comp, proj);
[🔗](#itemdecl:4)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
borrowed_iterator_t<R>
ranges::inplace_merge(Ep&& exec, R&& r, iterator_t<R> middle, Comp comp = {},
Proj proj = {});
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10252)
*Effects*: Equivalent to:return ranges::inplace_merge(std::forward<Ep>(exec), ranges::begin(r), middle,
ranges::end(r), comp, proj);

465
cppdraft/alg/min/max.md Normal file
View File

@@ -0,0 +1,465 @@
[alg.min.max]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.min.max)
### 26.8.9 Minimum and maximum [alg.min.max]
[🔗](#lib:min)
`template<class T>
constexpr const T& min(const T& a, const T& b);
template<class T, class Compare>
constexpr const T& min(const T& a, const T& b, Compare comp);
template<class T, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<const T*, Proj>> Comp = ranges::less>
constexpr const T& ranges::min(const T& a, const T& b, Comp comp = {}, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11284)
*Preconditions*: For the first form, T meets the[*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11289)
*Returns*: The smaller value[.](#2.sentence-1)
Returns the first argument when the arguments are equivalent[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11294)
*Complexity*: Exactly one comparison and two applications of the projection, if any[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11298)
*Remarks*: An invocation may explicitly specify
an argument for the template parameter T of the overloads in namespace std[.](#4.sentence-1)
[🔗](#lib:min_)
`template<class T>
constexpr T min(initializer_list<T> r);
template<class T, class Compare>
constexpr T min(initializer_list<T> r, Compare comp);
template<[copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]") T, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<const T*, Proj>> Comp = ranges::less>
constexpr T ranges::min(initializer_list<T> r, Comp comp = {}, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
requires [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, range_value_t<R>*>
constexpr range_value_t<R>
ranges::min(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
requires [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, range_value_t<R>*>
range_value_t<R>
ranges::min(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11328)
*Preconditions*: ranges::distance(r) > 0[.](#5.sentence-1)
For the overloads in namespace std,T meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#5.sentence-2)
For the first form, T meets the [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))[.](#5.sentence-3)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11336)
*Returns*: The smallest value in the input range[.](#6.sentence-1)
Returns a copy of the leftmost element
when several elements are equivalent to the smallest[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11342)
*Complexity*: Exactly ranges::distance(r) - 1 comparisons
and twice as many applications of the projection, if any[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11347)
*Remarks*: An invocation may explicitly specify
an argument for the template parameter T of the overloads in namespace std[.](#8.sentence-1)
[🔗](#lib:max)
`template<class T>
constexpr const T& max(const T& a, const T& b);
template<class T, class Compare>
constexpr const T& max(const T& a, const T& b, Compare comp);
template<class T, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<const T*, Proj>> Comp = ranges::less>
constexpr const T& ranges::max(const T& a, const T& b, Comp comp = {}, Proj proj = {});
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11367)
*Preconditions*: For the first form, T meets the[*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11372)
*Returns*: The larger value[.](#10.sentence-1)
Returns the first argument when the arguments are equivalent[.](#10.sentence-2)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11377)
*Complexity*: Exactly one comparison and two applications of the projection, if any[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11381)
*Remarks*: An invocation may explicitly specify
an argument for the template parameter T of the overloads in namespace std[.](#12.sentence-1)
[🔗](#lib:max_)
`template<class T>
constexpr T max(initializer_list<T> r);
template<class T, class Compare>
constexpr T max(initializer_list<T> r, Compare comp);
template<[copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]") T, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<const T*, Proj>> Comp = ranges::less>
constexpr T ranges::max(initializer_list<T> r, Comp comp = {}, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
requires [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, range_value_t<R>*>
constexpr range_value_t<R>
ranges::max(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
requires [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, range_value_t<R>*>
range_value_t<R>
ranges::max(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11411)
*Preconditions*: ranges::distance(r) > 0[.](#13.sentence-1)
For the overloads in namespace std,T meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#13.sentence-2)
For the first form, T meets the [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))[.](#13.sentence-3)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11419)
*Returns*: The largest value in the input range[.](#14.sentence-1)
Returns a copy of the leftmost element
when several elements are equivalent to the largest[.](#14.sentence-2)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11425)
*Complexity*: Exactly ranges::distance(r) - 1 comparisons
and twice as many applications of the projection, if any[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11430)
*Remarks*: An invocation may explicitly specify
an argument for the template parameter T of the overloads in namespace std[.](#16.sentence-1)
[🔗](#lib:minmax)
`template<class T>
constexpr pair<const T&, const T&> minmax(const T& a, const T& b);
template<class T, class Compare>
constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
template<class T, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<const T*, Proj>> Comp = ranges::less>
constexpr ranges::minmax_result<const T&>
ranges::minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {});
`
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11452)
*Preconditions*: For the first form, T meets the[*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))[.](#17.sentence-1)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11457)
*Returns*: {b, a} if b is smaller than a, and{a, b} otherwise[.](#18.sentence-1)
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11462)
*Complexity*: Exactly one comparison and two applications of the projection, if any[.](#19.sentence-1)
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11466)
*Remarks*: An invocation may explicitly specify
an argument for the template parameter T of the overloads in namespace std[.](#20.sentence-1)
[🔗](#lib:minmax_)
`template<class T>
constexpr pair<T, T> minmax(initializer_list<T> t);
template<class T, class Compare>
constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
template<[copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]") T, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<const T*, Proj>> Comp = ranges::less>
constexpr ranges::minmax_result<T>
ranges::minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
requires [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, range_value_t<R>*>
constexpr ranges::minmax_result<range_value_t<R>>
ranges::minmax(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
requires [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, range_value_t<R>*>
ranges::minmax_result<range_value_t<R>>
ranges::minmax(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11497)
*Preconditions*: ranges::distance(r) > 0[.](#21.sentence-1)
For the overloads in namespace std,T meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#21.sentence-2)
For the first form, type T meets the [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))[.](#21.sentence-3)
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11505)
*Returns*: Let X be the return type[.](#22.sentence-1)
Returns X{x, y},
where x is a copy of the leftmost element with the smallest value andy a copy of the rightmost element with the largest value
in the input range[.](#22.sentence-2)
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11513)
*Complexity*: At most (3/2)ranges::distance(r) applications
of the corresponding predicate
and twice as many applications of the projection, if any[.](#23.sentence-1)
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11519)
*Remarks*: An invocation may explicitly specify
an argument for the template parameter T of the overloads in namespace std[.](#24.sentence-1)
[🔗](#lib:min_element)
`template<class ForwardIterator>
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator min_element(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class Compare>
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
Compare comp);
template<class ExecutionPolicy, class ForwardIterator, class Compare>
ForwardIterator min_element(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
constexpr I ranges::min_element(I first, S last, Comp comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
constexpr borrowed_iterator_t<R>
ranges::min_element(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
I ranges::min_element(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
borrowed_iterator_t<R>
ranges::min_element(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[25](#25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11562)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#25.sentence-1)
[26](#26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11567)
*Returns*: The first iterator i in the range [first, last)
such that for every iterator j in the range [first, last),bool(invoke(comp, invoke(proj, *j), invoke(proj, *i))) is false[.](#26.sentence-1)
Returns last if first == last[.](#26.sentence-2)
[27](#27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11577)
*Complexity*: Exactly max(last - first - 1,0) comparisons and
twice as many projections[.](#27.sentence-1)
[🔗](#lib:max_element)
`template<class ForwardIterator>
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator max_element(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class Compare>
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
Compare comp);
template<class ExecutionPolicy, class ForwardIterator, class Compare>
ForwardIterator max_element(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
constexpr I ranges::max_element(I first, S last, Comp comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
constexpr borrowed_iterator_t<R>
ranges::max_element(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
I ranges::max_element(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
borrowed_iterator_t<R>
ranges::max_element(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[28](#28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11619)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#28.sentence-1)
[29](#29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11624)
*Returns*: The first iterator i in the range [first, last)
such that for every iterator j in the range [first, last),bool(invoke(comp, invoke(proj, *i), invoke(proj, *j))) is false[.](#29.sentence-1)
Returns last if first == last[.](#29.sentence-2)
[30](#30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11634)
*Complexity*: Exactly max(last - first - 1,0) comparisons and
twice as many projections[.](#30.sentence-1)
[🔗](#lib:minmax_element)
`template<class ForwardIterator>
constexpr pair<ForwardIterator, ForwardIterator>
minmax_element(ForwardIterator first, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator>
pair<ForwardIterator, ForwardIterator>
minmax_element(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class Compare>
constexpr pair<ForwardIterator, ForwardIterator>
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
template<class ExecutionPolicy, class ForwardIterator, class Compare>
pair<ForwardIterator, ForwardIterator>
minmax_element(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
constexpr ranges::minmax_element_result<I>
ranges::minmax_element(I first, S last, Comp comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
constexpr ranges::minmax_element_result<borrowed_iterator_t<R>>
ranges::minmax_element(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
ranges::minmax_element_result<I>
ranges::minmax_element(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
ranges::minmax_element_result<borrowed_iterator_t<R>>
ranges::minmax_element(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[31](#31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11680)
*Returns*: {first, first} if [first, last) is empty, otherwise{m, M}, where m is
the first iterator in [first, last) such that no iterator in the range refers
to a smaller element, and where M is the last iterator[204](#footnote-204 "This behavior intentionally differs from max_­element.") in [first, last) such that no iterator in the range refers to a larger element[.](#31.sentence-1)
[32](#32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11692)
*Complexity*: Let N be last - first[.](#32.sentence-1)
At most max(⌊32(N−1)⌋,0) comparisons and
twice as many applications of the projection, if any[.](#32.sentence-2)
[204)](#footnote-204)[204)](#footnoteref-204)
This behavior
intentionally differs from max_element[.](#footnote-204.sentence-1)

128
cppdraft/alg/mismatch.md Normal file
View File

@@ -0,0 +1,128 @@
[alg.mismatch]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.mismatch)
### 26.6.12 Mismatch [alg.mismatch]
[🔗](#lib:mismatch)
`template<class InputIterator1, class InputIterator2>
constexpr pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
pair<ForwardIterator1, ForwardIterator2>
mismatch(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
template<class InputIterator1, class InputIterator2,
class BinaryPredicate>
constexpr pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
pair<ForwardIterator1, ForwardIterator2>
mismatch(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, BinaryPredicate pred);
template<class InputIterator1, class InputIterator2>
constexpr pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
pair<ForwardIterator1, ForwardIterator2>
mismatch(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class InputIterator1, class InputIterator2,
class BinaryPredicate>
constexpr pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
pair<ForwardIterator1, ForwardIterator2>
mismatch(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr ranges::mismatch_result<I1, I2>
ranges::mismatch(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr ranges::mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
ranges::mismatch(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
ranges::mismatch_result<I1, I2>
ranges::mismatch(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
ranges::mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
ranges::mismatch(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5543)
Let last2 be first2 + (last1 - first1) for the overloads in namespace std with no parameter last2[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5547)
Let E be:
- [(2.1)](#2.1)
!(*(first1 + n) == *(first2 + n)) for the overloads with no parameter pred;
- [(2.2)](#2.2)
pred(*(first1 + n), *(first2 + n)) == false for the overloads with a parameter pred and
no parameter proj1;
- [(2.3)](#2.3)
!invoke(pred, invoke(proj1, *(first1 + n)), invoke(proj2, *(first2 + n))) for the overloads with both parameters pred and proj1[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5563)
Let N be min(last1 - first1, last2 - first2)[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5566)
*Returns*: { first1 + n, first2 + n },
where n is the smallest integer in [0, N) such that E holds,
or N if no such integer exists[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5572)
*Complexity*: At most N applications of the corresponding predicate and any projections[.](#5.sentence-1)

File diff suppressed because it is too large Load Diff

230
cppdraft/alg/move.md Normal file
View File

@@ -0,0 +1,230 @@
[alg.move]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.move)
### 26.7.2 Move [alg.move]
[🔗](#lib:move,algorithm)
`template<class InputIterator, class OutputIterator>
constexpr OutputIterator move(InputIterator first, InputIterator last,
OutputIterator result);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<I, O>
constexpr ranges::move_result<I, O>
ranges::move(I first, S last, O result);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<iterator_t<R>, O>
constexpr ranges::move_result<borrowed_iterator_t<R>, O>
ranges::move(R&& r, O result);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6685)
Let E(n) be
- [(1.1)](#1.1)
std::move(*(first + n)) for the overload in namespace std;
- [(1.2)](#1.2)
ranges::iter_move(first + n) for the overloads in namespace ranges[.](#1.sentence-1)
Let N be last - first[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6697)
*Preconditions*: result is not in the range [first, last)[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6701)
*Effects*: Moves elements in the range [first, last)
into the range [result, result + N)
starting from first and proceeding to last[.](#3.sentence-1)
For each non-negative integer n<N, performs *(result + n) = E(n)[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6708)
*Returns*:
- [(4.1)](#4.1)
result + N for the overload in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{last, result + N} for the overloads in namespace ranges[.](#4.2.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6719)
*Complexity*: Exactly N assignments[.](#5.sentence-1)
[🔗](#lib:move,algorithm_)
`template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2 move(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS>
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<I, O>
ranges::move_result<I, O>
ranges::move(Ep&& exec, I first, S last, O result, OutS result_last);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR>
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<iterator_t<R>, iterator_t<OutR>>
ranges::move_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::move(Ep&& exec, R&& r, OutR&& result_r);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6743)
Let E(n) be:
- [(6.1)](#6.1)
std::move(*(first + n)) for the overload in namespace std;
- [(6.2)](#6.2)
ranges::iter_move(first + n) for the overloads in namespace ranges[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6754)
Let result_last be result + (last - first) for the overloads in namespace std[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6758)
Let N be min(last - first, result_last - result)[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6761)
*Preconditions*: The ranges [first, last) and [result, result + N)
do not overlap[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6766)
*Effects*: Moves elements in the range [first, first + N)
into the range [result, result + N)[.](#10.sentence-1)
For each non-negative integer n<N,
performs *(result + n) = E(n)[.](#10.sentence-2)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6773)
*Returns*:
- [(11.1)](#11.1)
result + N for the overload in namespace std[.](#11.1.sentence-1)
- [(11.2)](#11.2)
{first + N, result + N} for the overloads in namespace ranges[.](#11.2.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6784)
*Complexity*: Exactly N assignments[.](#12.sentence-1)
[🔗](#lib:move_backward)
`template<class BidirectionalIterator1, class BidirectionalIterator2>
constexpr BidirectionalIterator2
move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
BidirectionalIterator2 result);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I2>
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<I1, I2>
constexpr ranges::move_backward_result<I1, I2>
ranges::move_backward(I1 first, S1 last, I2 result);
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I>
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<iterator_t<R>, I>
constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I>
ranges::move_backward(R&& r, I result);
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6807)
Let E(n) be
- [(13.1)](#13.1)
std::move(*(last - n)) for the overload in namespace std;
- [(13.2)](#13.2)
ranges::iter_move(last - n) for the overloads in namespace ranges[.](#13.sentence-1)
Let N be last - first[.](#13.sentence-2)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6819)
*Preconditions*: result is not in the range (first, last][.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6823)
*Effects*: Moves elements in the range [first, last)
into the range [result - N, result)
starting from last - 1 and proceeding to first[.](#15.sentence-1)[202](#footnote-202 "move_­backward can be used instead of move when last is in the range [result - N, result).")
For each positive integer n ≤ N,
performs *(result - n) = E(n)[.](#15.sentence-2)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6835)
*Returns*:
- [(16.1)](#16.1)
result - N for the overload in namespace std[.](#16.1.sentence-1)
- [(16.2)](#16.2)
{last, result - N} for the overloads in namespace ranges[.](#16.2.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6846)
*Complexity*: Exactly N assignments[.](#17.sentence-1)
[202)](#footnote-202)[202)](#footnoteref-202)
move_backward can be used instead of move when last is in the range [result - N, result)[.](#footnote-202.sentence-1)

56
cppdraft/alg/none/of.md Normal file
View File

@@ -0,0 +1,56 @@
[alg.none.of]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.none.of)
### 26.6.3 None of [alg.none.of]
[🔗](#lib:none_of)
`template<class InputIterator, class Predicate>
constexpr bool none_of(InputIterator first, InputIterator last, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
bool ranges::none_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
bool ranges::none_of(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4502)
Let E be:
- [(1.1)](#1.1)
pred(*i) for the overloads in namespace std;
- [(1.2)](#1.2)
invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4512)
*Returns*: false if E is true for some iterator i in the range [first, last), andtrue otherwise[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4518)
*Complexity*: At most last - first applications of the predicate and any projection[.](#3.sentence-1)

2147
cppdraft/alg/nonmodifying.md Normal file

File diff suppressed because it is too large Load Diff

110
cppdraft/alg/nth/element.md Normal file
View File

@@ -0,0 +1,110 @@
[alg.nth.element]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.nth.element)
### 26.8.3 Nth element [alg.nth.element]
[🔗](#lib:nth_element)
`template<class RandomAccessIterator>
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
RandomAccessIterator last);
template<class ExecutionPolicy, class RandomAccessIterator>
void nth_element(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator nth,
RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
RandomAccessIterator last, Compare comp);
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
void nth_element(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator nth,
RandomAccessIterator last, Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I
ranges::nth_element(I first, I nth, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
I ranges::nth_element(Ep&& exec, I first, I nth, S last, Comp comp = {}, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9320)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9325)
*Preconditions*: [first, nth) and [nth, last) are valid ranges[.](#2.sentence-1)
For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")), and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9335)
*Effects*: After nth_element the element in the position pointed to by nth is the element that would be in that position
if the whole range were sorted with respect to comp and proj,
unless nth == last[.](#3.sentence-1)
Also for every iterator i in the range [first, nth)
and every iterator j in the range [nth, last)
it holds that:bool(invoke(comp, invoke(proj, *j), invoke(proj, *i))) is false[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9346)
*Returns*: last for the overload in namespace ranges[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9350)
*Complexity*: For the non-parallel algorithm overloads, linear on average[.](#5.sentence-1)
For the parallel algorithm overloads, O(N) applications of
the predicate, and O(NlogN) swaps, where N=last - first[.](#5.sentence-2)
[🔗](#itemdecl:2)
`template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::nth_element(R&& r, iterator_t<R> nth, Comp comp = {}, Proj proj = {});
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9365)
*Effects*: Equivalent to:return ranges::nth_element(ranges::begin(r), nth, ranges::end(r), comp, proj);
[🔗](#itemdecl:3)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
borrowed_iterator_t<R>
ranges::nth_element(Ep&& exec, R&& r, iterator_t<R> nth, Comp comp = {}, Proj proj = {});
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9382)
*Effects*: Equivalent to:return ranges::nth_element(std::forward<Ep>(exec), ranges::begin(r), nth, ranges::end(r),
comp, proj);

429
cppdraft/alg/partitions.md Normal file
View File

@@ -0,0 +1,429 @@
[alg.partitions]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.partitions)
### 26.8.5 Partitions [alg.partitions]
[🔗](#lib:is_partitioned)
`template<class InputIterator, class Predicate>
constexpr bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
bool is_partitioned(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr bool ranges::is_partitioned(I first, S last, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr bool ranges::is_partitioned(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
bool ranges::is_partitioned(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
bool ranges::is_partitioned(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9659)
Let proj be identity{} for the overloads with no parameter named proj[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9663)
*Returns*: true if and only if the elements e of [first, last)
are partitioned with respect to the expressionbool(invoke(pred, invoke(proj, e)))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9669)
*Complexity*: Linear[.](#3.sentence-1)
At most last - first applications of pred and proj[.](#3.sentence-2)
[🔗](#lib:partition)
`template<class ForwardIterator, class Predicate>
constexpr ForwardIterator
partition(ForwardIterator first, ForwardIterator last, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
ForwardIterator
partition(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);
template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr subrange<I>
ranges::partition(I first, S last, Pred pred, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_subrange_t<R>
ranges::partition(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
subrange<I> ranges::partition(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_subrange_t<R> ranges::partition(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9704)
Let proj be identity{} for the overloads with no parameter named proj and let E(x) be bool(invoke(pred, invoke(proj, x)))[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9709)
*Preconditions*: For the overloads in namespace std,ForwardIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9715)
*Effects*: Places all the elements e in [first, last)
that satisfy E(e) before all the elements that do not[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9720)
*Returns*: Let i be an iterator such that E(*j) istrue for every iterator j in [first, i) andfalse for every iterator j in [i, last)[.](#7.sentence-1)
Returns:
- [(7.1)](#7.1)
i for the overloads in namespace std[.](#7.1.sentence-1)
- [(7.2)](#7.2)
{i, last} for the overloads in namespace ranges[.](#7.2.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9732)
*Complexity*: Let N=last - first:
- [(8.1)](#8.1)
For the non-parallel algorithm overloads,
exactly N applications of the predicate and projection[.](#8.1.sentence-1)
At most N/2 swaps if the type of first meets
the [*Cpp17BidirectionalIterator*](bidirectional.iterators#:Cpp17BidirectionalIterator "24.3.5.6Bidirectional iterators[bidirectional.iterators]") requirements
for the overloads in namespace std or
models [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") for the overloads in namespace ranges,
and at most N swaps otherwise[.](#8.1.sentence-2)
- [(8.2)](#8.2)
For the parallel algorithm overloads, O(NlogN) swaps and O(N) applications of the predicate[.](#8.2.sentence-1)
[🔗](#lib:stable_partition)
`template<class BidirectionalIterator, class Predicate>
BidirectionalIterator
constexpr stable_partition(BidirectionalIterator first, BidirectionalIterator last,
Predicate pred);
template<class ExecutionPolicy, class BidirectionalIterator, class Predicate>
BidirectionalIterator
stable_partition(ExecutionPolicy&& exec,
BidirectionalIterator first, BidirectionalIterator last, Predicate pred);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
constexpr subrange<I> ranges::stable_partition(I first, S last, Pred pred, Proj proj = {});
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_subrange_t<R> ranges::stable_partition(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
subrange<I>
ranges::stable_partition(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_subrange_t<R>
ranges::stable_partition(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9784)
Let proj be identity{} for the overloads with no parameter named proj and let E(x) be bool(invoke(pred, invoke(proj, x)))[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9789)
*Preconditions*: For the overloads in namespace std,BidirectionalIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9798)
*Effects*: Places all the elements e in [first, last)
that satisfy E(e) before all the elements that do not[.](#11.sentence-1)
The relative order of the elements in both groups is preserved[.](#11.sentence-2)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9804)
*Returns*: Let i be an iterator
such that for every iterator j in [first, i),E(*j) is true,
and for every iterator j in the range [i, last),E(*j) is false[.](#12.sentence-1)
Returns:
- [(12.1)](#12.1)
i for the overloads in namespace std[.](#12.1.sentence-1)
- [(12.2)](#12.2)
{i, last} for the overloads in namespace ranges[.](#12.2.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9817)
*Complexity*: Let N = last - first:
- [(13.1)](#13.1)
For the non-parallel algorithm overloads,
at most Nlog2N swaps,
but only O(N) swaps if there is enough extra memory[.](#13.1.sentence-1)
Exactly N applications of the predicate and projection[.](#13.1.sentence-2)
- [(13.2)](#13.2)
For the parallel algorithm overloads, O(NlogN) swaps and O(N) applications of the predicate[.](#13.2.sentence-1)
[🔗](#lib:partition_copy)
`template<class InputIterator, class OutputIterator1, class OutputIterator2, class Predicate>
constexpr pair<OutputIterator1, OutputIterator2>
partition_copy(InputIterator first, InputIterator last,
OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class ForwardIterator1,
class ForwardIterator2, class Predicate>
pair<ForwardIterator1, ForwardIterator2>
partition_copy(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
ForwardIterator1 out_true, ForwardIterator2 out_false, Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O1, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O2,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O1> && [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O2>
constexpr ranges::partition_copy_result<I, O1, O2>
ranges::partition_copy(I first, S last, O1 out_true, O2 out_false, Pred pred,
Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O1, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O2,
class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O1> &&
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O2>
constexpr ranges::partition_copy_result<borrowed_iterator_t<R>, O1, O2>
ranges::partition_copy(R&& r, O1 out_true, O2 out_false, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O1> OutS1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O2> OutS2,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O1> && [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O2>
ranges::partition_copy_result<I, O1, O2>
ranges::partition_copy(Ep&& exec, I first, S last, O1 out_true, OutS1 last_true,
O2 out_false, OutS2 last_false, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR2,
class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR1>> &&
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR2>>
ranges::partition_copy_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR1>,
borrowed_iterator_t<OutR2>>
ranges::partition_copy(Ep&& exec, R&& r, OutR1&& out_true_r, OutR2&& out_false_r,
Pred pred, Proj proj = {});
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9880)
Let proj be identity{} for the overloads with no parameter named proj and
let E(x) be bool(invoke(pred, invoke(proj, x)))[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9885)
For the overloads with no parameterslast_true, last_false, out_true_r, or out_false_r,
let
- [(15.1)](#15.1)
M be the number of iterators i in [first, last)
for which E(*i) is true,
and K be last - first - M;
- [(15.2)](#15.2)
last_true be out_true + M, and last_false be out_false + K[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9899)
For the overloads with parameterslast_true, last_false, out_true_r, or out_false_r,
let M be last_true - out_true and K be last_false - out_false[.](#16.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9905)
Let:
- [(17.1)](#17.1)
i1 be the iterator in [first, last)
for which E(*i1) is true and there are exactly M iterators j in [first, i1)
for which E(*j) is true,
or last if no such iterator exists;
- [(17.2)](#17.2)
i2 be the iterator in [first, last)
for which E(*i2) is false and there are exactly K iterators j in [first, i2)
for which E(*j) is false,
or last if no such iterator exists;
- [(17.3)](#17.3)
N be min(i1 - first, i2 - first)[.](#17.sentence-1)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9924)
*Mandates*: For the overloads in namespace std,
the expression *first is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General"))
to out_true and out_false[.](#18.sentence-1)
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9931)
*Preconditions*: The input range and output ranges do not overlap[.](#19.sentence-1)
[*Note [1](#note-1)*:
For the parallel algorithm overload in namespace std,
there can be a performance cost if first's value type
does not meet the *Cpp17CopyConstructible* requirements[.](#19.sentence-2)
For the parallel algorithm overloads in namespace ranges,
there can be a performance cost if first's value type
does not model [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]")[.](#19.sentence-3)
— *end note*]
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9944)
*Effects*: For each iterator i in [first, first + N),
copies *i to the output range [out_true, last_true)
if E(*i) is true, or
to the output range [out_false, last_false) otherwise[.](#20.sentence-1)
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9951)
*Returns*: Let o1 be the iterator past the last copied element
in the output range [out_true, last_true),
and o2 be the iterator past the last copied element
in the output range [out_false, last_false)[.](#21.sentence-1)
Returns:
- [(21.1)](#21.1)
{o1, o2} for the overloads in namespace std[.](#21.1.sentence-1)
- [(21.2)](#21.2)
{first + N, o1, o2} for the overloads in namespace ranges[.](#21.2.sentence-1)
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9963)
*Complexity*: At most last - first applications of pred and proj[.](#22.sentence-1)
[🔗](#lib:partition_point)
`template<class ForwardIterator, class Predicate>
constexpr ForwardIterator
partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr I ranges::partition_point(I first, S last, Pred pred, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_iterator_t<R>
ranges::partition_point(R&& r, Pred pred, Proj proj = {});
`
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9984)
Let proj be identity{} for the overloads with no parameter named proj and let E(x) be bool(invoke(pred, invoke(proj, x)))[.](#23.sentence-1)
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9989)
*Preconditions*: The elements e of [first, last)
are partitioned with respect to E(e)[.](#24.sentence-1)
[25](#25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9994)
*Returns*: An iterator mid such that E(*i) is true for all iterators i in [first, mid), andfalse for all iterators i in [mid, last)[.](#25.sentence-1)
[26](#26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10001)
*Complexity*: O(log(last - first)) applications
of pred and proj[.](#26.sentence-1)

View File

@@ -0,0 +1,151 @@
[alg.permutation.generators]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.permutation.generators)
### 26.8.13 Permutation generators [alg.permutation.generators]
[🔗](#lib:next_permutation)
`template<class BidirectionalIterator>
constexpr bool next_permutation(BidirectionalIterator first,
BidirectionalIterator last);
template<class BidirectionalIterator, class Compare>
constexpr bool next_permutation(BidirectionalIterator first,
BidirectionalIterator last, Compare comp);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr ranges::next_permutation_result<I>
ranges::next_permutation(I first, S last, Comp comp = {}, Proj proj = {});
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr ranges::next_permutation_result<borrowed_iterator_t<R>>
ranges::next_permutation(R&& r, Comp comp = {}, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11918)
Let comp be less{} and proj be identity{} for overloads with no parameters by those names[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11923)
*Preconditions*: For the overloads in namespace std,BidirectionalIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11929)
*Effects*: Takes a sequence defined by the range [first, last)
and transforms it into the next permutation[.](#3.sentence-1)
The next permutation is found by assuming that the set of all permutations
is lexicographically sorted with respect to comp and proj[.](#3.sentence-2)
If no such permutation exists,
transforms the sequence into the first permutation;
that is, the ascendingly-sorted one[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11939)
*Returns*: Let B be true if a next permutation was found and
otherwise false[.](#4.sentence-1)
Returns:
- [(4.1)](#4.1)
B for the overloads in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{ last, B } for the overloads in namespace ranges[.](#4.2.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11949)
*Complexity*: At most (last - first) / 2 swaps[.](#5.sentence-1)
[🔗](#lib:prev_permutation)
`template<class BidirectionalIterator>
constexpr bool prev_permutation(BidirectionalIterator first,
BidirectionalIterator last);
template<class BidirectionalIterator, class Compare>
constexpr bool prev_permutation(BidirectionalIterator first,
BidirectionalIterator last, Compare comp);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr ranges::prev_permutation_result<I>
ranges::prev_permutation(I first, S last, Comp comp = {}, Proj proj = {});
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr ranges::prev_permutation_result<borrowed_iterator_t<R>>
ranges::prev_permutation(R&& r, Comp comp = {}, Proj proj = {});
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11977)
Let comp be less{} and proj be identity{} for overloads with no parameters by those names[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11982)
*Preconditions*: For the overloads in namespace std,BidirectionalIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11988)
*Effects*: Takes a sequence defined by the range [first, last)
and transforms it into the previous permutation[.](#8.sentence-1)
The previous permutation is found by assuming that the set of all permutations
is lexicographically sorted with respect to comp and proj[.](#8.sentence-2)
If no such permutation exists,
transforms the sequence into the last permutation;
that is, the descendingly-sorted one[.](#8.sentence-3)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11998)
*Returns*: Let B be true if a previous permutation was found and
otherwise false[.](#9.sentence-1)
Returns:
- [(9.1)](#9.1)
B for the overloads in namespace std[.](#9.1.sentence-1)
- [(9.2)](#9.2)
{ last, B } for the overloads in namespace ranges[.](#9.2.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12008)
*Complexity*: At most (last - first) / 2 swaps[.](#10.sentence-1)

150
cppdraft/alg/rand.md Normal file
View File

@@ -0,0 +1,150 @@
[alg.rand]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.12 Specialized <random> algorithms [alg.rand]
### [26.12.1](#general) General [[alg.rand.general]](alg.rand.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14313)
The contents specified in [alg.rand]
are declared in the header [<random>](rand.synopsis#header:%3crandom%3e "29.5.2Header <random> synopsis[rand.synopsis]")[.](#general-1.sentence-1)
### [26.12.2](#generate) generate_random [[alg.rand.generate]](alg.rand.generate)
[🔗](#lib:generate_random)
`template<class R, class G>
requires [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<R, invoke_result_t<G&>> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>>
constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g);
`
[1](#generate-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14327)
*Effects*:
- [(1.1)](#generate-1.1)
Calls g.generate_random(std::forward<R>(r)) if this expression is well-formed[.](#generate-1.1.sentence-1)
- [(1.2)](#generate-1.2)
Otherwise, if R models [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]"),
fills r with ranges::size(r) values of
type invoke_result_t<G&> by performing
an unspecified number of invocations of
the form g() or g.generate_random(s),
if such an expression is well-formed for a value N and
an object s of type span<invoke_result_t<G&>, N>[.](#generate-1.2.sentence-1)
[*Note [1](#generate-note-1)*:
Values of N can differ between invocations[.](#generate-1.2.sentence-2)
— *end note*]
- [(1.3)](#generate-1.3)
Otherwise, calls ranges::generate(std::forward<R>(r), ref(g))[.](#generate-1.3.sentence-1)
[2](#generate-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14348)
*Returns*: ranges::end(r)[.](#generate-2.sentence-1)
[3](#generate-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14352)
*Remarks*: The effects of generate_random(r, g) shall be equivalent toranges::generate(std::forward<R>(r), ref(g))[.](#generate-3.sentence-1)
[*Note [2](#generate-note-2)*:
This implies that g.generate_random(a) fills a with the same values as produced by invocation of g()[.](#generate-3.sentence-2)
— *end note*]
[🔗](#lib:generate_random_)
`template<class G, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<invoke_result_t<G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S>
requires [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>>
constexpr O ranges::generate_random(O first, S last, G&& g);
`
[4](#generate-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14370)
*Effects*: Equivalent to:return generate_random(subrange<O, S>(std::move(first), last), g);
[🔗](#lib:generate_random__)
`template<class R, class G, class D>
requires [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<R, invoke_result_t<D&, G&>> && [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<D&, G&> &&
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>> &&
is_arithmetic_v<invoke_result_t<D&, G&>>
constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g, D&& d);
`
[5](#generate-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14388)
*Effects*:
- [(5.1)](#generate-5.1)
Calls d.generate_random(std::forward<R>(r), g) if this expression is well-formed[.](#generate-5.1.sentence-1)
- [(5.2)](#generate-5.2)
Otherwise, if R models [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]"),
fills r with ranges::size(r) values of
type invoke_result_t<D&, G&> by performing an unspecified number of invocations of
the form invoke(d, g) or d.generate_random(s, g),
if such an expression is well-formed
for a value N and
an object s of type span<invoke_result_t<D&, G&>, N>[.](#generate-5.2.sentence-1)
[*Note [3](#generate-note-3)*:
Values of N can differ between invocations[.](#generate-5.2.sentence-2)
— *end note*]
- [(5.3)](#generate-5.3)
Otherwise, callsranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); });
[6](#generate-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14413)
*Returns*: ranges::end(r)[.](#generate-6.sentence-1)
[7](#generate-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14417)
*Remarks*: The effects of generate_random(r, g, d) shall be equivalent toranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); })
[*Note [4](#generate-note-4)*:
This implies that d.generate_random(a, g) fills a with the values with the same random distribution
as produced by invocation of invoke(d, g)[.](#generate-7.sentence-1)
— *end note*]
[🔗](#lib:generate_random___)
`template<class G, class D, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<invoke_result_t<D&, G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<D&, G&> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>> &&
is_arithmetic_v<invoke_result_t<D&, G&>>
constexpr O ranges::generate_random(O first, S last, G&& g, D&& d);
`
[8](#generate-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14439)
*Effects*: Equivalent to:return generate_random(subrange<O, S>(std::move(first), last), g, d);

View File

@@ -0,0 +1,13 @@
[alg.rand.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.12 Specialized <random> algorithms [[alg.rand]](alg.rand#general)
### 26.12.1 General [alg.rand.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14313)
The contents specified in [[alg.rand]](alg.rand "26.12Specialized <random> algorithms") are declared in the header [<random>](rand.synopsis#header:%3crandom%3e "29.5.2Header <random> synopsis[rand.synopsis]")[.](#1.sentence-1)

View File

@@ -0,0 +1,141 @@
[alg.rand.generate]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.12 Specialized <random> algorithms [[alg.rand]](alg.rand#generate)
### 26.12.2 generate_random [alg.rand.generate]
[🔗](#lib:generate_random)
`template<class R, class G>
requires [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<R, invoke_result_t<G&>> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>>
constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14327)
*Effects*:
- [(1.1)](#1.1)
Calls g.generate_random(std::forward<R>(r)) if this expression is well-formed[.](#1.1.sentence-1)
- [(1.2)](#1.2)
Otherwise, if R models [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]"),
fills r with ranges::size(r) values of
type invoke_result_t<G&> by performing
an unspecified number of invocations of
the form g() or g.generate_random(s),
if such an expression is well-formed for a value N and
an object s of type span<invoke_result_t<G&>, N>[.](#1.2.sentence-1)
[*Note [1](#note-1)*:
Values of N can differ between invocations[.](#1.2.sentence-2)
— *end note*]
- [(1.3)](#1.3)
Otherwise, calls ranges::generate(std::forward<R>(r), ref(g))[.](#1.3.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14348)
*Returns*: ranges::end(r)[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14352)
*Remarks*: The effects of generate_random(r, g) shall be equivalent toranges::generate(std::forward<R>(r), ref(g))[.](#3.sentence-1)
[*Note [2](#note-2)*:
This implies that g.generate_random(a) fills a with the same values as produced by invocation of g()[.](#3.sentence-2)
— *end note*]
[🔗](#lib:generate_random_)
`template<class G, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<invoke_result_t<G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S>
requires [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>>
constexpr O ranges::generate_random(O first, S last, G&& g);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14370)
*Effects*: Equivalent to:return generate_random(subrange<O, S>(std::move(first), last), g);
[🔗](#lib:generate_random__)
`template<class R, class G, class D>
requires [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<R, invoke_result_t<D&, G&>> && [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<D&, G&> &&
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>> &&
is_arithmetic_v<invoke_result_t<D&, G&>>
constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g, D&& d);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14388)
*Effects*:
- [(5.1)](#5.1)
Calls d.generate_random(std::forward<R>(r), g) if this expression is well-formed[.](#5.1.sentence-1)
- [(5.2)](#5.2)
Otherwise, if R models [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]"),
fills r with ranges::size(r) values of
type invoke_result_t<D&, G&> by performing an unspecified number of invocations of
the form invoke(d, g) or d.generate_random(s, g),
if such an expression is well-formed
for a value N and
an object s of type span<invoke_result_t<D&, G&>, N>[.](#5.2.sentence-1)
[*Note [3](#note-3)*:
Values of N can differ between invocations[.](#5.2.sentence-2)
— *end note*]
- [(5.3)](#5.3)
Otherwise, callsranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); });
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14413)
*Returns*: ranges::end(r)[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14417)
*Remarks*: The effects of generate_random(r, g, d) shall be equivalent toranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); })
[*Note [4](#note-4)*:
This implies that d.generate_random(a, g) fills a with the values with the same random distribution
as produced by invocation of invoke(d, g)[.](#7.sentence-1)
— *end note*]
[🔗](#lib:generate_random___)
`template<class G, class D, [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<invoke_result_t<D&, G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S>
requires [invocable](concept.invocable#concept:invocable "18.7.2Concept invocable[concept.invocable]")<D&, G&> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_cvref_t<G>> &&
is_arithmetic_v<invoke_result_t<D&, G&>>
constexpr O ranges::generate_random(O first, S last, G&& g, D&& d);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L14439)
*Effects*: Equivalent to:return generate_random(subrange<O, S>(std::move(first), last), g, d);

View File

@@ -0,0 +1,106 @@
[alg.random.sample]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.random.sample)
### 26.7.12 Sample [alg.random.sample]
[🔗](#lib:sample)
`template<class PopulationIterator, class SampleIterator,
class Distance, class UniformRandomBitGenerator>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n,
UniformRandomBitGenerator&& g);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Gen>
requires ([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I> || [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]")<O>) &&
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> &&
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_reference_t<Gen>>
O ranges::sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Gen>
requires ([forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]")<R> || [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]")<O>) &&
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O> &&
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_reference_t<Gen>>
O ranges::sample(R&& r, O out, range_difference_t<R> n, Gen&& g);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8410)
*Mandates*: For the overload in namespace std,Distance is an integer type and*first is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to out[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8416)
*Preconditions*: out is not in the range [first, last)[.](#2.sentence-1)
For the overload in namespace std:
- [(2.1)](#2.1)
PopulationIterator meets
the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#2.1.sentence-1)
- [(2.2)](#2.2)
SampleIterator meets
the [*Cpp17OutputIterator*](output.iterators#:Cpp17OutputIterator "24.3.5.4Output iterators[output.iterators]") requirements ([[output.iterators]](output.iterators "24.3.5.4Output iterators"))[.](#2.2.sentence-1)
- [(2.3)](#2.3)
SampleIterator meets
the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7Random access iterators[random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators"))
unless PopulationIterator models [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") ([[iterator.concept.forward]](iterator.concept.forward "24.3.4.11Concept forward_­iterator"))[.](#2.3.sentence-1)
- [(2.4)](#2.4)
remove_reference_t<UniformRandomBitGenerator> meets
the requirements of a uniform random bit generator type ([[rand.req.urng]](rand.req.urng "29.5.3.3Uniform random bit generator requirements"))[.](#2.4.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8437)
*Effects*: Copies min(last - first, n) elements (the [*sample*](#def:sample "26.7.12Sample[alg.random.sample]"))
from [first, last) (the [*population*](#def:population "26.7.12Sample[alg.random.sample]")) to out such that each possible sample has equal probability of appearance[.](#3.sentence-1)
[*Note [1](#note-1)*:
Algorithms that obtain such effects include [*selection sampling*](#def:selection_sampling) and [*reservoir sampling*](#def:reservoir_sampling)[.](#3.sentence-2)
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8447)
*Returns*: The end of the resulting sample range[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8451)
*Complexity*: O(last - first)[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8455)
*Remarks*:
- [(6.1)](#6.1)
For the overload in namespace std,
stable if and only if PopulationIterator models [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")[.](#6.1.sentence-1)
For the first overload in namespace ranges,
stable if and only if I models [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")[.](#6.1.sentence-2)
- [(6.2)](#6.2)
To the extent that the implementation of this function makes use
of random numbers, the object g serves as
the implementation's source of randomness[.](#6.2.sentence-1)

View File

@@ -0,0 +1,68 @@
[alg.random.shuffle]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.random.shuffle)
### 26.7.13 Shuffle [alg.random.shuffle]
[🔗](#lib:shuffle)
`template<class RandomAccessIterator, class UniformRandomBitGenerator>
void shuffle(RandomAccessIterator first,
RandomAccessIterator last,
UniformRandomBitGenerator&& g);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Gen>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I> &&
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_reference_t<Gen>>
I ranges::shuffle(I first, S last, Gen&& g);
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Gen>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>> &&
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3Uniform random bit generator requirements[rand.req.urng]")<remove_reference_t<Gen>>
borrowed_iterator_t<R> ranges::shuffle(R&& r, Gen&& g);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8491)
*Preconditions*: For the overload in namespace std:
- [(1.1)](#1.1)
RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))[.](#1.1.sentence-1)
- [(1.2)](#1.2)
The type remove_reference_t<UniformRandomBitGenerator> meets
the uniform random bit generator ([[rand.req.urng]](rand.req.urng "29.5.3.3Uniform random bit generator requirements")) requirements[.](#1.2.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8503)
*Effects*: Permutes the elements in the range [first, last)
such that each possible permutation of those elements
has equal probability of appearance[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8509)
*Returns*: last for the overloads in namespace ranges[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8513)
*Complexity*: Exactly (last - first) - 1 swaps[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8517)
*Remarks*: To the extent that the implementation of this function makes use
of random numbers, the object referenced by g shall serve as
the implementation's source of randomness[.](#5.sentence-1)

339
cppdraft/alg/remove.md Normal file
View File

@@ -0,0 +1,339 @@
[alg.remove]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.remove)
### 26.7.8 Remove [alg.remove]
[🔗](#lib:remove)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr ForwardIterator remove(ForwardIterator first, ForwardIterator last,
const T& value);
template<class ExecutionPolicy, class ForwardIterator,
class T = iterator_traits<ForwardIterator>::value_type>
ForwardIterator remove(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
const T& value);
template<class ForwardIterator, class Predicate>
constexpr ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
Predicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
ForwardIterator remove_if(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Predicate pred);
template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr borrowed_subrange_t<R>
ranges::remove(R&& r, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, class T = projected_value_t<I, Proj>>
requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
subrange<I>
ranges::remove(Ep&& exec, I first, S last, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to,
projected<iterator_t<R>, Proj>, const T*>
borrowed_subrange_t<R>
ranges::remove(Ep&& exec, R&& r, const T& value, Proj proj = {});
template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_subrange_t<R>
ranges::remove_if(R&& r, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
subrange<I>
ranges::remove_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_subrange_t<R>
ranges::remove_if(Ep&& exec, R&& r, Pred pred, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7594)
Let E be
- [(1.1)](#1.1)
bool(*i == value) for remove;
- [(1.2)](#1.2)
bool(pred(*i)) for remove_if;
- [(1.3)](#1.3)
bool(invoke(proj, *i) == value) for ranges::remove;
- [(1.4)](#1.4)
bool(invoke(pred, invoke(proj, *i))) for ranges::remove_if[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7603)
*Preconditions*: For the algorithms in namespace std,
the type of *first meets the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7609)
*Effects*: Eliminates all the elements referred to by iterator i in the range [first, last) for which E holds[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7614)
*Returns*: Let j be the end of the resulting range[.](#4.sentence-1)
Returns:
- [(4.1)](#4.1)
j for the overloads in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{j, last} for the overloads in namespace ranges[.](#4.2.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7622)
*Complexity*: Exactly last - first applications
of the corresponding predicate and any projection[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7627)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7631)
[*Note [1](#note-1)*:
Each element in the range [ret, last),
where ret is the returned value,
has a valid but unspecified state,
because the algorithms can eliminate elements
by moving from elements that were originally in that range[.](#7.sentence-1)
— *end note*]
[🔗](#lib:remove_copy)
`template<class InputIterator, class OutputIterator,
class T = iterator_traits<InputIterator>::value_type>
constexpr OutputIterator
remove_copy(InputIterator first, InputIterator last,
OutputIterator result, const T& value);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class T = iterator_traits<ForwardIterator1>::value_type>
ForwardIterator2
remove_copy(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, const T& value);
template<class InputIterator, class OutputIterator, class Predicate>
constexpr OutputIterator
remove_copy_if(InputIterator first, InputIterator last,
OutputIterator result, Predicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class Predicate>
ForwardIterator2
remove_copy_if(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, Predicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
class Proj = identity, class T = projected_value_t<I, Proj>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
constexpr ranges::remove_copy_result<I, O>
ranges::remove_copy(I first, S last, O result, const T& value, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr ranges::remove_copy_result<borrowed_iterator_t<R>, O>
ranges::remove_copy(R&& r, O result, const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS,
class Proj = identity, class T = projected_value_t<I, Proj>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*>
ranges::remove_copy_result<I, O>
ranges::remove_copy(Ep&& exec, I first, S last, O result, OutS result_last,
const T& value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR,
class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to,
projected<iterator_t<R>, Proj>, const T*>
ranges::remove_copy_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::remove_copy(Ep&& exec, R&& r, OutR&& result_r, const T& value, Proj proj = {});
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
constexpr ranges::remove_copy_if_result<I, O>
ranges::remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O>
constexpr ranges::remove_copy_if_result<borrowed_iterator_t<R>, O>
ranges::remove_copy_if(R&& r, O result, Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
ranges::remove_copy_if_result<I, O>
ranges::remove_copy_if(Ep&& exec, I first, S last, O result, OutS result_last,
Pred pred, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR,
class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>>
ranges::remove_copy_if_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::remove_copy_if(Ep&& exec, R&& r, OutR&& result_r, Pred pred, Proj proj = {});
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7723)
Let E(i) be
- [(8.1)](#8.1)
bool(*i == value) for remove_copy;
- [(8.2)](#8.2)
bool(pred(*i)) for remove_copy_if;
- [(8.3)](#8.3)
bool(invoke(proj, *i) == value) for ranges::remove_copy;
- [(8.4)](#8.4)
bool(invoke(pred, invoke(proj, *i))) for ranges::remove_copy_if[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7732)
Let:
- [(9.1)](#9.1)
M be the number of iterators i in [first, last)
for which E(i) is false;
- [(9.2)](#9.2)
result_last be result + M for the overloads with no parameter result_last or result_r;
- [(9.3)](#9.3)
N be min(M, result_last - result)[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7745)
*Mandates*: *first is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to result[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7749)
*Preconditions*: The ranges [first, last) and [result, result + N)
do not overlap[.](#11.sentence-1)
[*Note [2](#note-2)*:
For the parallel algorithm overloads in namespace std,
there can be a performance cost
if iterator_traits<ForwardIterator1>::value_type does not meet
the *Cpp17MoveConstructible* (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) requirements[.](#11.sentence-2)
For the parallel algorithm overloads in namespace ranges,
there can be a performance cost
if iter_value_t<I> does not model [move_constructible](concept.moveconstructible#concept:move_constructible "18.4.13Concept move_­constructible[concept.moveconstructible]")[.](#11.sentence-3)
— *end note*]
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7763)
*Effects*: Copies the first N elements referred to by the iterator i in the range [first, last) for which E(i) is false into the range [result, result + N)[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7769)
*Returns*:
- [(13.1)](#13.1)
result + N,
for the algorithms in namespace std[.](#13.1.sentence-1)
- [(13.2)](#13.2)
{last, result + N},
for the algorithms in namespace ranges,
if N is equal to M[.](#13.2.sentence-1)
- [(13.3)](#13.3)
Otherwise, {j, result_last},
for the algorithms in namespace ranges,
where j is the iterator in [first, last)
for which E(j) is false and there are exactly N iterators i in [first, j)
for which E(i) is false[.](#13.3.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7788)
*Complexity*: At most last - first applications
of the corresponding predicate and any projection[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7793)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#15.sentence-1)

309
cppdraft/alg/replace.md Normal file
View File

@@ -0,0 +1,309 @@
[alg.replace]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.replace)
### 26.7.5 Replace [alg.replace]
[🔗](#lib:replace)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr void replace(ForwardIterator first, ForwardIterator last,
const T& old_value, const T& new_value);
template<class ExecutionPolicy, class ForwardIterator,
class T = iterator_traits<ForwardIterator>::value_type>
void replace(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
const T& old_value, const T& new_value);
template<class ForwardIterator, class Predicate,
class T = iterator_traits<ForwardIterator>::value_type>
constexpr void replace_if(ForwardIterator first, ForwardIterator last,
Predicate pred, const T& new_value);
template<class ExecutionPolicy, class ForwardIterator, class Predicate,
class T = iterator_traits<ForwardIterator>::value_type>
void replace_if(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Predicate pred, const T& new_value);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T1 = projected_value_t<I, Proj>, class T2 = T1>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<I, const T2&> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*>
constexpr I
ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<R>, const T2&> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
constexpr borrowed_iterator_t<R>
ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = T1>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<I, const T2&> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*>
I ranges::replace(Ep&& exec, I first, S last,
const T1& old_value, const T2& new_value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<R>, const T2&> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to,
projected<iterator_t<R>, Proj>, const T1*>
borrowed_iterator_t<R>
ranges::replace(Ep&& exec, R&& r, const T1& old_value, const T2& new_value,
Proj proj = {});
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
class T = projected_value_t<I, Proj>,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<I, const T&>
constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<R>, const T&>
constexpr borrowed_iterator_t<R>
ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity, class T = projected_value_t<I, Proj>,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<I, const T&>
I ranges::replace_if(Ep&& exec, I first, S last, Pred pred,
const T& new_value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<R>, const T&>
borrowed_iterator_t<R>
ranges::replace_if(Ep&& exec, R&& r, Pred pred, const T& new_value, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7203)
Let E(i) be
- [(1.1)](#1.1)
bool(*i == old_value) for replace;
- [(1.2)](#1.2)
bool(pred(*i)) for replace_if;
- [(1.3)](#1.3)
bool(invoke(proj, *i) == old_value) for ranges::replace;
- [(1.4)](#1.4)
bool(invoke(pred, invoke(proj, *i))) for ranges::replace_if[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7212)
*Mandates*: new_value is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to first[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7216)
*Effects*: Substitutes elements referred by the iterator i in the range [first, last) with new_value,
when E(i) is true[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7222)
*Returns*: last for the overloads in namespace ranges[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7226)
*Complexity*: Exactly last - first applications
of the corresponding predicate and any projection[.](#5.sentence-1)
[🔗](#lib:replace_copy)
`template<class InputIterator, class OutputIterator, class T>
constexpr OutputIterator
replace_copy(InputIterator first, InputIterator last,
OutputIterator result,
const T& old_value, const T& new_value);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
ForwardIterator2
replace_copy(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result,
const T& old_value, const T& new_value);
template<class InputIterator, class OutputIterator, class Predicate, class T>
constexpr OutputIterator
replace_copy_if(InputIterator first, InputIterator last,
OutputIterator result,
Predicate pred, const T& new_value);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class Predicate, class T>
ForwardIterator2
replace_copy_if(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result,
Predicate pred, const T& new_value);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class O,
class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = iter_value_t<O>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*> &&
[output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T2&>
constexpr ranges::replace_copy_result<I, O>
ranges::replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class O, class Proj = identity,
class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = iter_value_t<O>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
&& [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T2&>
constexpr ranges::replace_copy_result<borrowed_iterator_t<R>, O>
ranges::replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS,
class Proj = identity,
class T1 = projected_value_t<I, Proj>, class T2 = iter_value_t<O>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*> &&
[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, const T2&>
ranges::replace_copy_result<I, O>
ranges::replace_copy(Ep&& exec, I first, S last, O result, OutS result_last,
const T1& old_value, const T2& new_value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR,
class Proj = identity, class T1 = projected_value_t<iterator_t<R>, Proj>,
class T2 = range_value_t<OutR>>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>> &&
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to,
projected<iterator_t<R>, Proj>, const T1*> &&
[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<OutR>, const T2&>
ranges::replace_copy_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::replace_copy(Ep&& exec, R&& r, OutR&& result_r, const T1& old_value,
const T2& new_value, Proj proj = {});
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S,class O, class T = iter_value_t<O>,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> && [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T&>
constexpr ranges::replace_copy_if_result<I, O>
ranges::replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class O, class T = iter_value_t<O>, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O> && [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T&>
constexpr ranges::replace_copy_if_result<borrowed_iterator_t<R>, O>
ranges::replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS, class T = iter_value_t<O>,
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, const T&>
ranges::replace_copy_if_result<I, O>
ranges::replace_copy_if(Ep&& exec, I first, S last, O result, OutS result_last,
Pred pred, const T& new_value, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR,
class T = range_value_t<OutR>, class Proj = identity,
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>> &&
[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<OutR, const T&>
ranges::replace_copy_if_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::replace_copy_if(Ep&& exec, R&& r, OutR&& result_r, Pred pred, const T& new_value,
Proj proj = {});
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7330)
Let E(i) be
- [(6.1)](#6.1)
bool(*(first + (i - result)) == old_value) for replace_copy;
- [(6.2)](#6.2)
bool(pred(*(first + (i - result)))) for replace_copy_if;
- [(6.3)](#6.3)
bool(invoke(proj, *(first + (i - result))) == old_value) for ranges::replace_copy;
- [(6.4)](#6.4)
bool(invoke(pred, invoke(proj, *(first + (i - result))))) for ranges::replace_copy_if[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7343)
Let:
- [(7.1)](#7.1)
result_last be result + (last - first) for the overloads with no parameter result_last or result_r;
- [(7.2)](#7.2)
N be min(last - first, result_last - result)[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7353)
*Mandates*: The results of the expressions *first and new_value are writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to result[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7358)
*Preconditions*: The ranges [first, last) and [result, result + N)
do not overlap[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7363)
*Effects*: Assigns through every iterator i in the range [result, result + N)
a new corresponding value
- [(10.1)](#10.1)
new_value if E(i) is true or
- [(10.2)](#10.2)
*(first + (i - result)) otherwise[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7373)
*Returns*:
- [(11.1)](#11.1)
result + N for the overloads in namespace std[.](#11.1.sentence-1)
- [(11.2)](#11.2)
{first + N, result + N} for the overloads in namespace ranges[.](#11.2.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7384)
*Complexity*: Exactly N applications
of the corresponding predicate and any projection[.](#12.sentence-1)

166
cppdraft/alg/req.md Normal file
View File

@@ -0,0 +1,166 @@
[alg.req]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req)
### 24.3.7 Common algorithm requirements [alg.req]
#### [24.3.7.1](#general) General [[alg.req.general]](alg.req.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2545)
There are several additional iterator concepts that are commonly applied
to families of algorithms[.](#general-1.sentence-1)
These group together iterator requirements
of algorithm families[.](#general-1.sentence-2)
There are three relational concepts that specify
how element values are transferred between[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") and [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]") types:[indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]"),[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]"), and[indirectly_swappable](#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")[.](#general-1.sentence-3)
There are three relational concepts for rearrangements:[permutable](#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]"),[mergeable](#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]"), and[sortable](#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")[.](#general-1.sentence-4)
There is one relational concept for comparing values from different sequences:[indirectly_comparable](#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")[.](#general-1.sentence-5)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2562)
[*Note [1](#general-note-1)*:
The ranges::less function object type
used in the concepts below imposes constraints on the concepts' arguments
in addition to those that appear in the concepts' bodies ([[range.cmp]](range.cmp "22.10.9Concept-constrained comparisons"))[.](#general-2.sentence-1)
— *end note*]
#### [24.3.7.2](#ind.move) Concept indirectly_movable [[alg.req.ind.move]](alg.req.ind.move)
[1](#ind.move-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2571)
The [indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") concept specifies the relationship between
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]") type
between which values may be moved[.](#ind.move-1.sentence-1)
template<class In, class Out>concept [indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_rvalue_reference_t<In>>;
[2](#ind.move-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2583)
The [indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") concept augments[indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") with additional requirements enabling
the transfer to be performed through an intermediate object of the[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type's value type[.](#ind.move-2.sentence-1)
template<class In, class Out>concept [indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") =[indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_value_t<In>> &&[movable](concepts.object#concept:movable "18.6Object concepts[concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<In>, iter_rvalue_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8Concept assignable_­from[concept.assignable]")<iter_value_t<In>&, iter_rvalue_reference_t<In>>;
[3](#ind.move-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2599)
Let i be a dereferenceable value of type In[.](#ind.move-3.sentence-1)
In and Out model [indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<In, Out> only if after the initialization of the object obj initer_value_t<In> obj(ranges::iter_move(i));obj is equal to the value previously denoted by *i[.](#ind.move-3.sentence-2)
Ifiter_rvalue_reference_t<In> is an rvalue reference type,
the resulting state of the value denoted by *i is
valid but unspecified ([[lib.types.movedfrom]](lib.types.movedfrom "16.4.6.17Moved-from state of library types"))[.](#ind.move-3.sentence-3)
#### [24.3.7.3](#ind.copy) Concept indirectly_copyable [[alg.req.ind.copy]](alg.req.ind.copy)
[1](#ind.copy-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2613)
The [indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") concept specifies the relationship between
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]") type
between which values may be copied[.](#ind.copy-1.sentence-1)
template<class In, class Out>concept [indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_reference_t<In>>;
[2](#ind.copy-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2625)
The [indirectly_copyable_storable](#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") concept augments[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") with additional requirements enabling
the transfer to be performed through an intermediate object of the[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type's value type[.](#ind.copy-2.sentence-1)
It also requires the capability
to make copies of values[.](#ind.copy-2.sentence-2)
template<class In, class Out>concept [indirectly_copyable_storable](#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") =[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, const iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_value_t<In>&&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, const iter_value_t<In>&&> &&[copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<In>, iter_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8Concept assignable_­from[concept.assignable]")<iter_value_t<In>&, iter_reference_t<In>>;
[3](#ind.copy-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2645)
Let i be a dereferenceable value of type In[.](#ind.copy-3.sentence-1)
In and Out model [indirectly_copyable_storable](#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<In, Out> only if after the initialization of the object obj initer_value_t<In> obj(*i);obj is equal to the value previously denoted by *i[.](#ind.copy-3.sentence-2)
Ifiter_reference_t<In> is an rvalue reference type, the resulting state
of the value denoted by *i is
valid but unspecified ([[lib.types.movedfrom]](lib.types.movedfrom "16.4.6.17Moved-from state of library types"))[.](#ind.copy-3.sentence-3)
#### [24.3.7.4](#ind.swap) Concept indirectly_swappable [[alg.req.ind.swap]](alg.req.ind.swap)
[1](#ind.swap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2659)
The [indirectly_swappable](#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]") concept specifies a swappable relationship
between the values referenced by two [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") types[.](#ind.swap-1.sentence-1)
template<class I1, class I2 = I1>concept [indirectly_swappable](#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<I1> && [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<I2> &&requires(const I1 i1, const I2 i2) { ranges::iter_swap(i1, i1);
ranges::iter_swap(i2, i2);
ranges::iter_swap(i1, i2);
ranges::iter_swap(i2, i1); };
#### [24.3.7.5](#ind.cmp) Concept indirectly_comparable [[alg.req.ind.cmp]](alg.req.ind.cmp)
[1](#ind.cmp-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2677)
The [indirectly_comparable](#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]") concept specifies
the common requirements of algorithms that
compare values from two different sequences[.](#ind.cmp-1.sentence-1)
template<class I1, class I2, class R, class P1 = identity, class P2 = identity>concept [indirectly_comparable](#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]") =[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<R, projected<I1, P1>, projected<I2, P2>>;
#### [24.3.7.6](#permutable) Concept permutable [[alg.req.permutable]](alg.req.permutable)
[1](#permutable-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2691)
The [permutable](#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") concept specifies the common requirements
of algorithms that reorder elements in place by moving or swapping them[.](#permutable-1.sentence-1)
template<class I>concept [permutable](#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") =[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I> &&[indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<I, I> &&[indirectly_swappable](#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")<I, I>;
#### [24.3.7.7](#mergeable) Concept mergeable [[alg.req.mergeable]](alg.req.mergeable)
[1](#mergeable-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2705)
The [mergeable](#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]") concept specifies the requirements of algorithms
that merge sorted sequences into an output sequence by copying elements[.](#mergeable-1.sentence-1)
template<class I1, class I2, class Out, class R = ranges::less, class P1 = identity, class P2 = identity>concept [mergeable](#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]") =[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]")<I1> &&[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]")<I2> &&[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]")<Out> &&[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I1, Out> &&[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I2, Out> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<R, projected<I1, P1>, projected<I2, P2>>;
#### [24.3.7.8](#sortable) Concept sortable [[alg.req.sortable]](alg.req.sortable)
[1](#sortable-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2723)
The [sortable](#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]") concept specifies the common requirements of
algorithms that permute sequences into ordered sequences (e.g., sort)[.](#sortable-1.sentence-1)
template<class I, class R = ranges::less, class P = identity>concept [sortable](#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]") =[permutable](#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<R, projected<I, P>>;

View File

@@ -0,0 +1,38 @@
[alg.req.general]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.general)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#general)
#### 24.3.7.1 General [alg.req.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2545)
There are several additional iterator concepts that are commonly applied
to families of algorithms[.](#1.sentence-1)
These group together iterator requirements
of algorithm families[.](#1.sentence-2)
There are three relational concepts that specify
how element values are transferred between[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") and [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]") types:[indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]"),[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]"), and[indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")[.](#1.sentence-3)
There are three relational concepts for rearrangements:[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]"),[mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]"), and[sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")[.](#1.sentence-4)
There is one relational concept for comparing values from different sequences:[indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")[.](#1.sentence-5)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2562)
[*Note [1](#note-1)*:
The ranges::less function object type
used in the concepts below imposes constraints on the concepts' arguments
in addition to those that appear in the concepts' bodies ([[range.cmp]](range.cmp "22.10.9Concept-constrained comparisons"))[.](#2.sentence-1)
— *end note*]

View File

@@ -0,0 +1,19 @@
[alg.req.ind.cmp]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.ind.cmp)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#ind.cmp)
#### 24.3.7.5 Concept indirectly_comparable [alg.req.ind.cmp]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2677)
The [indirectly_comparable](#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]") concept specifies
the common requirements of algorithms that
compare values from two different sequences[.](#1.sentence-1)
template<class I1, class I2, class R, class P1 = identity, class P2 = identity>concept [indirectly_comparable](#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]") =[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<R, projected<I1, P1>, projected<I2, P2>>;

View File

@@ -0,0 +1,43 @@
[alg.req.ind.copy]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.ind.copy)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#ind.copy)
#### 24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2613)
The [indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") concept specifies the relationship between
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]") type
between which values may be copied[.](#1.sentence-1)
template<class In, class Out>concept [indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_reference_t<In>>;
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2625)
The [indirectly_copyable_storable](#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") concept augments[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") with additional requirements enabling
the transfer to be performed through an intermediate object of the[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type's value type[.](#2.sentence-1)
It also requires the capability
to make copies of values[.](#2.sentence-2)
template<class In, class Out>concept [indirectly_copyable_storable](#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]") =[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, const iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_value_t<In>&&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, const iter_value_t<In>&&> &&[copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<In>, iter_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8Concept assignable_­from[concept.assignable]")<iter_value_t<In>&, iter_reference_t<In>>;
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2645)
Let i be a dereferenceable value of type In[.](#3.sentence-1)
In and Out model [indirectly_copyable_storable](#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<In, Out> only if after the initialization of the object obj initer_value_t<In> obj(*i);obj is equal to the value previously denoted by *i[.](#3.sentence-2)
Ifiter_reference_t<In> is an rvalue reference type, the resulting state
of the value denoted by *i is
valid but unspecified ([[lib.types.movedfrom]](lib.types.movedfrom "16.4.6.17Moved-from state of library types"))[.](#3.sentence-3)

View File

@@ -0,0 +1,40 @@
[alg.req.ind.move]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.ind.move)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#ind.move)
#### 24.3.7.2 Concept indirectly_movable [alg.req.ind.move]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2571)
The [indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") concept specifies the relationship between
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]") type
between which values may be moved[.](#1.sentence-1)
template<class In, class Out>concept [indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_rvalue_reference_t<In>>;
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2583)
The [indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") concept augments[indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") with additional requirements enabling
the transfer to be performed through an intermediate object of the[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") type's value type[.](#2.sentence-1)
template<class In, class Out>concept [indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]") =[indirectly_movable](#concept:indirectly_movable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<Out, iter_value_t<In>> &&[movable](concepts.object#concept:movable "18.6Object concepts[concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<In>, iter_rvalue_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8Concept assignable_­from[concept.assignable]")<iter_value_t<In>&, iter_rvalue_reference_t<In>>;
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2599)
Let i be a dereferenceable value of type In[.](#3.sentence-1)
In and Out model [indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<In, Out> only if after the initialization of the object obj initer_value_t<In> obj(ranges::iter_move(i));obj is equal to the value previously denoted by *i[.](#3.sentence-2)
Ifiter_rvalue_reference_t<In> is an rvalue reference type,
the resulting state of the value denoted by *i is
valid but unspecified ([[lib.types.movedfrom]](lib.types.movedfrom "16.4.6.17Moved-from state of library types"))[.](#3.sentence-3)

View File

@@ -0,0 +1,21 @@
[alg.req.ind.swap]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.ind.swap)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#ind.swap)
#### 24.3.7.4 Concept indirectly_swappable [alg.req.ind.swap]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2659)
The [indirectly_swappable](#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]") concept specifies a swappable relationship
between the values referenced by two [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]") types[.](#1.sentence-1)
template<class I1, class I2 = I1>concept [indirectly_swappable](#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<I1> && [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2Concept indirectly_­readable[iterator.concept.readable]")<I2> &&requires(const I1 i1, const I2 i2) { ranges::iter_swap(i1, i1);
ranges::iter_swap(i2, i2);
ranges::iter_swap(i1, i2);
ranges::iter_swap(i2, i1); };

View File

@@ -0,0 +1,18 @@
[alg.req.mergeable]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.mergeable)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#mergeable)
#### 24.3.7.7 Concept mergeable [alg.req.mergeable]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2705)
The [mergeable](#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]") concept specifies the requirements of algorithms
that merge sorted sequences into an output sequence by copying elements[.](#1.sentence-1)
template<class I1, class I2, class Out, class R = ranges::less, class P1 = identity, class P2 = identity>concept [mergeable](#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]") =[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]")<I1> &&[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]")<I2> &&[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]")<Out> &&[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I1, Out> &&[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I2, Out> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<R, projected<I1, P1>, projected<I2, P2>>;

View File

@@ -0,0 +1,18 @@
[alg.req.permutable]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.permutable)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#permutable)
#### 24.3.7.6 Concept permutable [alg.req.permutable]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2691)
The [permutable](#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") concept specifies the common requirements
of algorithms that reorder elements in place by moving or swapping them[.](#1.sentence-1)
template<class I>concept [permutable](#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") =[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I> &&[indirectly_movable_storable](alg.req.ind.move#concept:indirectly_movable_storable "24.3.7.2Concept indirectly_­movable[alg.req.ind.move]")<I, I> &&[indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")<I, I>;

View File

@@ -0,0 +1,18 @@
[alg.req.sortable]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#alg.req.sortable)
### 24.3.7 Common algorithm requirements [[alg.req]](alg.req#sortable)
#### 24.3.7.8 Concept sortable [alg.req.sortable]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2723)
The [sortable](#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]") concept specifies the common requirements of
algorithms that permute sequences into ordered sequences (e.g., sort)[.](#1.sentence-1)
template<class I, class R = ranges::less, class P = identity>concept [sortable](#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]") =[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<R, projected<I, P>>;

167
cppdraft/alg/reverse.md Normal file
View File

@@ -0,0 +1,167 @@
[alg.reverse]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.reverse)
### 26.7.10 Reverse [alg.reverse]
[🔗](#lib:reverse)
`template<class BidirectionalIterator>
constexpr void reverse(BidirectionalIterator first, BidirectionalIterator last);
template<class ExecutionPolicy, class BidirectionalIterator>
void reverse(ExecutionPolicy&& exec,
BidirectionalIterator first, BidirectionalIterator last);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
constexpr I ranges::reverse(I first, S last);
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_iterator_t<R> ranges::reverse(R&& r);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
I ranges::reverse(Ep&& exec, I first, S last);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_iterator_t<R> ranges::reverse(Ep&& exec, R&& r);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8064)
*Preconditions*: For the overloads in namespace std,BidirectionalIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8070)
*Effects*: For each non-negative integer i < (last - first) / 2,
applies std::iter_swap, orranges::iter_swap for the overloads in namespace ranges,
to all pairs of iterators first + i, (last - i) - 1[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8077)
*Returns*: last for the overloads in namespace ranges[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8081)
*Complexity*: Exactly (last - first)/2 swaps[.](#4.sentence-1)
[🔗](#lib:reverse_copy)
`template<class BidirectionalIterator, class OutputIterator>
constexpr OutputIterator
reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
OutputIterator result);
template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
ForwardIterator
reverse_copy(ExecutionPolicy&& exec,
BidirectionalIterator first, BidirectionalIterator last,
ForwardIterator result);
template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
constexpr ranges::reverse_copy_result<I, O>
ranges::reverse_copy(I first, S last, O result);
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O>
constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
ranges::reverse_copy(R&& r, O result);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8109)
Let N be last - first[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8112)
*Preconditions*: The ranges [first, last) and [result, result + N)
do not overlap[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8117)
*Effects*: Copies the range [first, last) to the range [result, result + N)
such that for every non-negative integer i < N the following assignment takes place:*(result + N - 1 - i) = *(first + i)[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8124)
*Returns*:
- [(8.1)](#8.1)
result + N for the overloads in namespace std[.](#8.1.sentence-1)
- [(8.2)](#8.2)
{last, result + N} for the overloads in namespace ranges[.](#8.2.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8133)
*Complexity*: Exactly N assignments[.](#9.sentence-1)
[🔗](#itemdecl:3)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
ranges::reverse_copy_truncated_result<I, O>
ranges::reverse_copy(Ep&& exec, I first, S last, O result,
OutS result_last);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>>
ranges::reverse_copy_truncated_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::reverse_copy(Ep&& exec, R&& r, OutR&& result_r);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8152)
Let N be min(last - first, result_last - result),
and let *NEW_FIRST* be first + (last - first) - N[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8156)
*Preconditions*: The ranges [first, last) and [result, result + N)
do not overlap[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8161)
*Effects*: Copies the range [*NEW_FIRST*, last)
to the range [result, result + N)
such that for every non-negative integer i<N the following assignment takes place:*(result + N - 1 - i) = *(*NEW_FIRST* + i)[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8169)
*Returns*: {last, *NEW_FIRST*, result + N}[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8173)
*Complexity*: Exactly N assignments[.](#14.sentence-1)

236
cppdraft/alg/rotate.md Normal file
View File

@@ -0,0 +1,236 @@
[alg.rotate]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.rotate)
### 26.7.11 Rotate [alg.rotate]
[🔗](#lib:rotate)
`template<class ForwardIterator>
constexpr ForwardIterator
rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator
rotate(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator middle, ForwardIterator last);
template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S>
constexpr subrange<I> ranges::rotate(I first, I middle, S last);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
subrange<I> ranges::rotate(Ep&& exec, I first, I middle, S last);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8198)
*Preconditions*: [first, middle) and [middle, last) are valid ranges[.](#1.sentence-1)
For the overloads in namespace std,ForwardIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")), and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8208)
*Effects*: For each non-negative integer i < (last - first),
places the element from the position first + i into position first + (i + (last - middle)) % (last - first)[.](#2.sentence-1)
[*Note [1](#note-1)*:
This is a left rotate[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8217)
*Returns*:
- [(3.1)](#3.1)
first + (last - middle) for the overloads in namespace std[.](#3.1.sentence-1)
- [(3.2)](#3.2)
{first + (last - middle), last} for the overload in namespace ranges[.](#3.2.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8228)
*Complexity*: At most last - first swaps[.](#4.sentence-1)
[🔗](#itemdecl:2)
`template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_subrange_t<R> ranges::rotate(R&& r, iterator_t<R> middle);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8240)
*Effects*: Equivalent to:return ranges::rotate(ranges::begin(r), middle, ranges::end(r));
[🔗](#itemdecl:3)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_subrange_t<R> ranges::rotate(Ep&& exec, R&& r, iterator_t<R> middle);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8253)
*Effects*: Equivalent to:return ranges::rotate(std::forward<Ep>(exec), ranges::begin(r), middle, ranges::end(r));
[🔗](#lib:rotate_copy)
`template<class ForwardIterator, class OutputIterator>
constexpr OutputIterator
rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
rotate_copy(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
ForwardIterator2 result);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
constexpr ranges::rotate_copy_result<I, O>
ranges::rotate_copy(I first, I middle, S last, O result);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8280)
Let N be last - first[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8283)
*Preconditions*: [first, middle) and [middle, last) are valid ranges[.](#8.sentence-1)
The ranges [first, last) and [result, result + N)
do not overlap[.](#8.sentence-2)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8289)
*Effects*: Copies the range [first, last) to the range [result, result + N)
such that for each non-negative integer i<N the following assignment takes place:*(result + i) = *(first + (i + (middle - first)) % N)[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8296)
*Returns*:
- [(10.1)](#10.1)
result + N for the overloads in namespace std[.](#10.1.sentence-1)
- [(10.2)](#10.2)
{last, result + N} for the overload in namespace ranges[.](#10.2.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8305)
*Complexity*: Exactly N assignments[.](#11.sentence-1)
[🔗](#itemdecl:5)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
ranges::rotate_copy_truncated_result<I, O>
ranges::rotate_copy(Ep&& exec, I first, I middle, S last, O result, OutS result_last);
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8319)
Let M be last - first and N be min(M, result_last - result)[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8323)
*Preconditions*: [first, middle) and [middle, last)
are valid ranges[.](#13.sentence-1)
The ranges [first, last) and [result, result + N)
do not overlap[.](#13.sentence-2)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8330)
*Effects*: Copies the range [first, last)
to the range [result, result + N)
such that for each non-negative integer i<N the following assignment takes place:*(result + i) = *(first + (i + (middle - first)) % M)[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8338)
*Returns*:
- [(15.1)](#15.1)
{middle + N, first, result + N} if N is less than last - middle[.](#15.1.sentence-1)
- [(15.2)](#15.2)
Otherwise, {last, first + (N + (middle - first)) % M, result + N}[.](#15.2.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8349)
*Complexity*: Exactly N assignments[.](#16.sentence-1)
[🔗](#itemdecl:6)
`template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O>
constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
ranges::rotate_copy(R&& r, iterator_t<R> middle, O result);
`
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8362)
*Effects*: Equivalent to:return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), std::move(result));
[🔗](#itemdecl:7)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>>
ranges::rotate_copy_truncated_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::rotate_copy(Ep&& exec, R&& r, iterator_t<R> middle, OutR&& result_r);
`
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8378)
*Effects*: Equivalent to:return ranges::rotate_copy(std::forward<Ep>(exec), ranges::begin(r), middle, ranges::end(r),
ranges::begin(result_r), ranges::end(result_r));

232
cppdraft/alg/search.md Normal file
View File

@@ -0,0 +1,232 @@
[alg.search]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.search)
### 26.6.15 Search [alg.search]
[🔗](#lib:search)
`template<class ForwardIterator1, class ForwardIterator2>
constexpr ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator1
search(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
constexpr ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
ForwardIterator1
search(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5839)
*Returns*: The first iterator i in the range [first1, last1 - (last2 - first2)]
such that
for every non-negative integer n less than last2 - first2 the following corresponding conditions hold:*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false[.](#1.sentence-1)
Returns first1 if [first2, last2) is empty,
otherwise returns last1 if no such iterator is found[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5849)
*Complexity*: At most (last1 - first1) * (last2 - first2) applications
of the corresponding predicate[.](#2.sentence-1)
[🔗](#lib:search_)
`template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I2,
[sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2, class Pred = ranges::equal_to,
class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr subrange<I1>
ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R2, class Pred = ranges::equal_to,
class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr borrowed_subrange_t<R1>
ranges::search(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
subrange<I1>
ranges::search(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
borrowed_subrange_t<R1>
ranges::search(Ep&& exec, R1&& r1, R2&& r2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5887)
*Returns*:
- [(3.1)](#3.1)
{i, i + (last2 - first2)},
where i is
the first iterator in the range [first1, last1 - (last2 - first2)]
such that
for every non-negative integer n less than last2 - first2 the conditionbool(invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n)))) is true.
- [(3.2)](#3.2)
Returns {last1, last1} if no such iterator exists.
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5905)
*Complexity*: At most (last1 - first1) * (last2 - first2) applications
of the corresponding predicate and projections[.](#4.sentence-1)
[🔗](#lib:search_n)
`template<class ForwardIterator, class Size, class T = iterator_traits<ForwardIterator>::value_type>
constexpr ForwardIterator
search_n(ForwardIterator first, ForwardIterator last,
Size count, const T& value);
template<class ExecutionPolicy, class ForwardIterator, class Size,
class T = iterator_traits<ForwardIterator>::value_type>
ForwardIterator
search_n(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Size count, const T& value);
template<class ForwardIterator, class Size, class T = iterator_traits<ForwardIterator>::value_type,
class BinaryPredicate>
constexpr ForwardIterator
search_n(ForwardIterator first, ForwardIterator last,
Size count, const T& value,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator, class Size,
class T = iterator_traits<ForwardIterator>::value_type,
class BinaryPredicate>
ForwardIterator
search_n(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Size count, const T& value,
BinaryPredicate pred);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5942)
*Mandates*: The type Size is convertible to an integral type ([[conv.integral]](conv.integral "7.3.9Integral conversions"), [[class.conv]](class.conv "11.4.8Conversions"))[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5947)
Let E be pred(*(i + n), value) != false for the overloads with a parameter pred,
and *(i + n) == value otherwise[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5952)
*Returns*: The first iterator i in the range [first, last - count]
such that for every non-negative integer n less than count the condition E is true[.](#7.sentence-1)
Returns last if no such iterator is found[.](#7.sentence-2)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5959)
*Complexity*: At most last - first applications of the corresponding predicate[.](#8.sentence-1)
[🔗](#lib:search_n_)
`template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S,
class Pred = ranges::equal_to, class Proj = identity,
class T = projected_value_t<I, Proj>>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I, const T*, Pred, Proj>
constexpr subrange<I>
ranges::search_n(I first, S last, iter_difference_t<I> count,
const T& value, Pred pred = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Pred = ranges::equal_to,
class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R>, const T*, Pred, Proj>
constexpr borrowed_subrange_t<R>
ranges::search_n(R&& r, range_difference_t<R> count,
const T& value, Pred pred = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Pred = ranges::equal_to, class Proj = identity,
class T = projected_value_t<I, Proj>>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I, const T*, Pred, Proj>
subrange<I>
ranges::search_n(Ep&& exec, I first, S last, iter_difference_t<I> count,
const T& value, Pred pred = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Pred = ranges::equal_to,
class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R>, const T*, Pred, Proj>
borrowed_subrange_t<R>
ranges::search_n(Ep&& exec, R&& r, range_difference_t<R> count,
const T& value, Pred pred = {}, Proj proj = {});
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5996)
*Returns*: {i, i + count} where i is the first iterator in the range [first, last - count]
such that for every non-negative integer n less than count,
the following condition holds:invoke(pred, invoke(proj, *(i + n)), value)[.](#9.sentence-1)
Returns {last, last} if no such iterator is found[.](#9.sentence-2)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6005)
*Complexity*: At most last - first applications
of the corresponding predicate and projection[.](#10.sentence-1)
[🔗](#lib:search__)
`template<class ForwardIterator, class Searcher>
constexpr ForwardIterator
search(ForwardIterator first, ForwardIterator last, const Searcher& searcher);
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6019)
*Effects*: Equivalent to: return searcher(first, last).first;
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6023)
*Remarks*: Searcher need not meet the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#12.sentence-1)

View File

@@ -0,0 +1,698 @@
[alg.set.operations]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.set.operations)
### 26.8.7 Set operations on sorted structures [alg.set.operations]
#### [26.8.7.1](#general) General [[alg.set.operations.general]](alg.set.operations.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10265)
Subclause [alg.set.operations] defines all the basic set operations on sorted structures[.](#general-1.sentence-1)
They also work with multisets ([[multiset]](multiset "23.4.7Class template multiset"))
containing multiple copies of equivalent elements[.](#general-1.sentence-2)
The semantics of the set operations are generalized to multisets
in a standard way by defining set_union to contain the maximum number of occurrences of every element,set_intersection to contain the minimum, and so on[.](#general-1.sentence-3)
#### [26.8.7.2](#includes) includes [[includes]](includes)
[🔗](#lib:includes)
`template<class InputIterator1, class InputIterator2>
constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
bool includes(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template<class InputIterator1, class InputIterator2, class Compare>
constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare comp);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Compare>
bool includes(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Proj1 = identity, class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I1, Proj1>,
projected<I2, Proj2>> Comp = ranges::less>
constexpr bool ranges::includes(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, class Proj1 = identity,
class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
constexpr bool ranges::includes(R1&& r1, R2&& r2, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Proj1 = identity, class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I1, Proj1>, projected<I2, Proj2>> Comp =
ranges::less>
bool ranges::includes(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Proj1 = identity, class Proj2 = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
bool ranges::includes(Ep&& exec, R1&& r1, R2&& r2,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#includes-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10325)
Let comp be less{},proj1 be identity{}, andproj2 be identity{},
for the overloads with no parameters by those names[.](#includes-1.sentence-1)
[2](#includes-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10331)
*Preconditions*: The ranges [first1, last1) and [first2, last2) are sorted
with respect to comp and proj1 or proj2, respectively[.](#includes-2.sentence-1)
[3](#includes-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10336)
*Returns*: true if and only if [first2, last2) is a subsequence of [first1, last1)[.](#includes-3.sentence-1)
[*Note [1](#includes-note-1)*:
A sequence S is a subsequence of another sequence T if S can be obtained
from T by removing some, all, or none of T's elements and keeping the
remaining elements in the same order[.](#includes-3.sentence-2)
— *end note*]
[4](#includes-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10346)
*Complexity*: At most 2 * ((last1 - first1) + (last2 - first2)) - 1 comparisons and applications of each projection[.](#includes-4.sentence-1)
#### [26.8.7.3](#set.union) set_union [[set.union]](set.union)
[🔗](#lib:set_union)
`template<class InputIterator1, class InputIterator2, class OutputIterator>
constexpr OutputIterator
set_union(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator>
ForwardIterator
set_union(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result);
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
constexpr OutputIterator
set_union(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare comp);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator, class Compare>
ForwardIterator
set_union(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result, Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
constexpr ranges::set_union_result<I1, I2, O>
ranges::set_union(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
constexpr ranges::set_union_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
ranges::set_union(R1&& r1, R2&& r2, O result, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
ranges::set_union_result<I1, I2, O>
ranges::set_union(Ep&& exec, I1 first1, S1 last1,
I2 first2, S2 last2, O result, OutS result_last,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, iterator_t<OutR>, Comp, Proj1, Proj2>
ranges::set_union_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>,
borrowed_iterator_t<OutR>>
ranges::set_union(Ep&& exec, R1&& r1, R2&& r2, OutR&& result_r, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#set.union-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10416)
Let:
- [(1.1)](#set.union-1.1)
comp be less{},
and proj1 and proj2 be identity{} for the overloads with no parameters by those names;
- [(1.2)](#set.union-1.2)
M be last1 - first1 plus the number of elements in [first2, last2)
that are not present in [first1, last1);
- [(1.3)](#set.union-1.3)
result_last be result + M for the overloads with no parameter result_last or result_r;
- [(1.4)](#set.union-1.4)
N be min(M, result_last - result)[.](#set.union-1.sentence-1)
[2](#set.union-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10433)
*Preconditions*: The ranges [first1, last1) and [first2, last2) are sorted
with respect to comp and proj1 or proj2, respectively[.](#set.union-2.sentence-1)
The resulting range does not overlap with either of the original ranges[.](#set.union-2.sentence-2)
[3](#set.union-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10439)
*Effects*: Constructs a sorted union of N elements from the two ranges;
that is, the set of elements that are present in one or both of the ranges[.](#set.union-3.sentence-1)
[4](#set.union-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10444)
*Returns*:
- [(4.1)](#set.union-4.1)
result_last for the overloads in namespace std[.](#set.union-4.1.sentence-1)
- [(4.2)](#set.union-4.2)
{last1, last2, result + N} for the overloads in namespace ranges,
if N is equal to M[.](#set.union-4.2.sentence-1)
- [(4.3)](#set.union-4.3)
Otherwise, {j1, j2, result_last} for the overloads in namespace ranges,
where the iterators j1 and j2 point to positions past the last copied or skipped elements
in [first1, last1) and [first2, last2), respectively[.](#set.union-4.3.sentence-1)
[5](#set.union-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10462)
*Complexity*: At most 2 * ((last1 - first1) + (last2 - first2)) - 1 comparisons and applications of each projection[.](#set.union-5.sentence-1)
[6](#set.union-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10467)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#set.union-6.sentence-1)
If [first1, last1) contains m elements
that are equivalent to each other and
[first2, last2) contains n elements
that are equivalent to them,
then all m elements from the first range
are copied to the output range, in order, and
then the final max(n−m,0) elements from the second range
are copied to the output range, in order[.](#set.union-6.sentence-2)
#### [26.8.7.4](#set.intersection) set_intersection [[set.intersection]](set.intersection)
[🔗](#lib:set_intersection)
`template<class InputIterator1, class InputIterator2,
class OutputIterator>
constexpr OutputIterator
set_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator>
ForwardIterator
set_intersection(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result);
template<class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
constexpr OutputIterator
set_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare comp);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator, class Compare>
ForwardIterator
set_intersection(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result, Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
constexpr ranges::set_intersection_result<I1, I2, O>
ranges::set_intersection(I1 first1, S1 last1, I2 first2, S2 last2, O result,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
constexpr ranges::set_intersection_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
ranges::set_intersection(R1&& r1, R2&& r2, O result,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
ranges::set_intersection_result<I1, I2, O>
ranges::set_intersection(Ep&& exec, I1 first1, S1 last1,
I2 first2, S2 last2, O result, OutS result_last,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, iterator_t<OutR>, Comp, Proj1, Proj2>
ranges::set_intersection_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>,
borrowed_iterator_t<OutR>>
ranges::set_intersection(Ep&& exec, R1&& r1, R2&& r2, OutR&& result_r, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#set.intersection-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10546)
Let:
- [(1.1)](#set.intersection-1.1)
comp be less{},
and proj1 and proj2 be identity{} for the overloads with no parameters by those names;
- [(1.2)](#set.intersection-1.2)
M be the number of elements in [first1, last1)
that are present in [first2, last2);
- [(1.3)](#set.intersection-1.3)
result_last be result + M for the overloads with no parameter result_last or result_r;
- [(1.4)](#set.intersection-1.4)
N be min(M, result_last - result)[.](#set.intersection-1.sentence-1)
[2](#set.intersection-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10563)
*Preconditions*: The ranges [first1, last1) and [first2, last2) are sorted
with respect to comp and proj1 or proj2, respectively[.](#set.intersection-2.sentence-1)
The resulting range does not overlap with either of the original ranges[.](#set.intersection-2.sentence-2)
[3](#set.intersection-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10569)
*Effects*: Constructs a sorted intersection of N elements from the two ranges;
that is, the set of elements that are present in both of the ranges[.](#set.intersection-3.sentence-1)
[4](#set.intersection-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10574)
*Returns*:
- [(4.1)](#set.intersection-4.1)
result_last for the overloads in namespace std[.](#set.intersection-4.1.sentence-1)
- [(4.2)](#set.intersection-4.2)
{last1, last2, result + N} for the overloads in namespace ranges,
if N is equal to M[.](#set.intersection-4.2.sentence-1)
- [(4.3)](#set.intersection-4.3)
Otherwise, {j1, j2, result_last} for the overloads in namespace ranges,
where the iterators j1 and j2 point to positions past the last copied or skipped elements
in [first1, last1) and [first2, last2), respectively[.](#set.intersection-4.3.sentence-1)
[5](#set.intersection-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10592)
*Complexity*: At most 2 * ((last1 - first1) + (last2 - first2)) - 1 comparisons and applications of each projection[.](#set.intersection-5.sentence-1)
[6](#set.intersection-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10597)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#set.intersection-6.sentence-1)
If [first1, last1) contains m elements
that are equivalent to each other and
[first2, last2) contains n elements
that are equivalent to them,
the first min(m,n) elements
are copied from the first range to the output range, in order[.](#set.intersection-6.sentence-2)
#### [26.8.7.5](#set.difference) set_difference [[set.difference]](set.difference)
[🔗](#lib:set_difference)
`template<class InputIterator1, class InputIterator2,
class OutputIterator>
constexpr OutputIterator
set_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator>
ForwardIterator
set_difference(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result);
template<class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
constexpr OutputIterator
set_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare comp);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator, class Compare>
ForwardIterator
set_difference(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result, Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
constexpr ranges::set_difference_result<I1, O>
ranges::set_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
constexpr ranges::set_difference_result<borrowed_iterator_t<R1>, O>
ranges::set_difference(R1&& r1, R2&& r2, O result,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
ranges::set_difference_result<I1, O>
ranges::set_difference(Ep&& exec, I1 first1, S1 last1,
I2 first2, S2 last2, O result, OutS result_last,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, iterator_t<OutR>, Comp, Proj1, Proj2>
ranges::set_difference_result<borrowed_iterator_t<R1>, borrowed_iterator_t<OutR>>
ranges::set_difference(Ep&& exec, R1&& r1, R2&& r2, OutR&& result_r, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#set.difference-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10673)
Let:
- [(1.1)](#set.difference-1.1)
comp be less{},
and proj1 and proj2 be identity{} for the overloads with no parameters by those names;
- [(1.2)](#set.difference-1.2)
M be the number of elements in [first1, last1)
that are not present in [first2, last2);
- [(1.3)](#set.difference-1.3)
result_last be result + M for the overloads with no parameter result_last or result_r;
- [(1.4)](#set.difference-1.4)
N be min(M, result_last - result)[.](#set.difference-1.sentence-1)
[2](#set.difference-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10690)
*Preconditions*: The ranges [first1, last1) and [first2, last2) are sorted
with respect to comp and proj1 or proj2, respectively[.](#set.difference-2.sentence-1)
The resulting range does not overlap with either of the original ranges[.](#set.difference-2.sentence-2)
[3](#set.difference-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10696)
*Effects*: Copies N elements of the range [first1, last1)
which are not present in the range [first2, last2)
to the range [result, result + N)[.](#set.difference-3.sentence-1)
The elements in the constructed range are sorted[.](#set.difference-3.sentence-2)
[4](#set.difference-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10703)
*Returns*:
- [(4.1)](#set.difference-4.1)
result_last for the overloads in namespace std[.](#set.difference-4.1.sentence-1)
- [(4.2)](#set.difference-4.2)
{last1, result + N} for the overloads in namespace ranges,
if N is equal to M[.](#set.difference-4.2.sentence-1)
- [(4.3)](#set.difference-4.3)
Otherwise, {j1, result_last} for the overloads in namespace ranges,
where the iterator j1 points to positions past the last copied or skipped elements
in [first1, last1) and [first2, last2), respectively[.](#set.difference-4.3.sentence-1)
[5](#set.difference-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10721)
*Complexity*: At most 2 * ((last1 - first1) + (last2 - first2)) - 1 comparisons and applications of each projection[.](#set.difference-5.sentence-1)
[6](#set.difference-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10726)
*Remarks*: If [first1, last1) contains m elements
that are equivalent to each other and
[first2, last2) contains n elements
that are equivalent to them,
the last max(m−n,0) elements from [first1, last1)
are copied to the output range, in order[.](#set.difference-6.sentence-1)
#### [26.8.7.6](#set.symmetric.difference) set_symmetric_difference [[set.symmetric.difference]](set.symmetric.difference)
[🔗](#lib:set_symmetric_difference)
`template<class InputIterator1, class InputIterator2,
class OutputIterator>
constexpr OutputIterator
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator>
ForwardIterator
set_symmetric_difference(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result);
template<class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
constexpr OutputIterator
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare comp);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator, class Compare>
ForwardIterator
set_symmetric_difference(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
ForwardIterator result, Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
constexpr ranges::set_symmetric_difference_result<I1, I2, O>
ranges::set_symmetric_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
Comp comp = {}, Proj1 proj1 = {},
Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
constexpr ranges::set_symmetric_difference_result<borrowed_iterator_t<R1>,
borrowed_iterator_t<R2>, O>
ranges::set_symmetric_difference(R1&& r1, R2&& r2, O result, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<I1, I2, O, Comp, Proj1, Proj2>
ranges::set_symmetric_difference_result<I1, I2, O>
ranges::set_symmetric_difference(Ep&& exec, I1 first1, S1 last1,
I2 first2, S2 last2, O result, OutS result_last,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7Concept mergeable[alg.req.mergeable]")<iterator_t<R1>, iterator_t<R2>, iterator_t<OutR>, Comp, Proj1, Proj2>
ranges::set_symmetric_difference_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>,
borrowed_iterator_t<OutR>>
ranges::set_symmetric_difference(Ep&& exec, R1&& r1, R2&& r2, OutR&& result_r,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#set.symmetric.difference-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10804)
Let:
- [(1.1)](#set.symmetric.difference-1.1)
comp be less{},
and proj1 and proj2 be identity{} for the overloads with no parameters by those names;
- [(1.2)](#set.symmetric.difference-1.2)
K be the number of elements in [first1, last1) that are not present in [first2, last2)[.](#set.symmetric.difference-1.2.sentence-1)
- [(1.3)](#set.symmetric.difference-1.3)
M be the number of elements in [first2, last2) that are not present in [first1, last1)[.](#set.symmetric.difference-1.3.sentence-1)
- [(1.4)](#set.symmetric.difference-1.4)
result_last be result + M + K for the overloads with no parameter result_last or result_r;
- [(1.5)](#set.symmetric.difference-1.5)
N be min(K+M, result_last - result)[.](#set.symmetric.difference-1.5.sentence-1)
[2](#set.symmetric.difference-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10822)
*Preconditions*: The ranges [first1, last1) and [first2, last2) are sorted
with respect to comp and proj1 or proj2, respectively[.](#set.symmetric.difference-2.sentence-1)
The resulting range does not overlap with either of the original ranges[.](#set.symmetric.difference-2.sentence-2)
[3](#set.symmetric.difference-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10828)
*Effects*: Copies the elements of the range [first1, last1)
that are not present in the range [first2, last2),
and the elements of the range [first2, last2)
that are not present in the range [first1, last1)
to the range [result, result + N)[.](#set.symmetric.difference-3.sentence-1)
The elements in the constructed range are sorted[.](#set.symmetric.difference-3.sentence-2)
[4](#set.symmetric.difference-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10837)
*Returns*:
- [(4.1)](#set.symmetric.difference-4.1)
result_last for the overloads in namespace std[.](#set.symmetric.difference-4.1.sentence-1)
- [(4.2)](#set.symmetric.difference-4.2)
{last1, last2, result + N} for the overloads in namespace ranges,
if N is equal to M+K[.](#set.symmetric.difference-4.2.sentence-1)
- [(4.3)](#set.symmetric.difference-4.3)
Otherwise, {j1, j2, result_last} for the overloads in namespace ranges,
where the iterators j1 and j2 point to positions past the last copied or skipped elements
in [first1, last1) and [first2, last2), respectively[.](#set.symmetric.difference-4.3.sentence-1)
[5](#set.symmetric.difference-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10855)
*Complexity*: At most 2 * ((last1 - first1) + (last2 - first2)) - 1 comparisons and applications of each projection[.](#set.symmetric.difference-5.sentence-1)
[6](#set.symmetric.difference-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10860)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#set.symmetric.difference-6.sentence-1)
If [first1, last1) contains m elements
that are equivalent to each other and
[first2, last2) contains n elements
that are equivalent to them,
then |m−n| of those elements shall be copied to the output range:
the last m−n of these elements from [first1, last1) if m>n, and
the last n−m of these elements from [first2, last2) if m<n[.](#set.symmetric.difference-6.sentence-2)
In either case, the elements are copied in order[.](#set.symmetric.difference-6.sentence-3)

View File

@@ -0,0 +1,21 @@
[alg.set.operations.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.set.operations.general)
### 26.8.7 Set operations on sorted structures [[alg.set.operations]](alg.set.operations#general)
#### 26.8.7.1 General [alg.set.operations.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10265)
Subclause [[alg.set.operations]](alg.set.operations "26.8.7Set operations on sorted structures") defines all the basic set operations on sorted structures[.](#1.sentence-1)
They also work with multisets ([[multiset]](multiset "23.4.7Class template multiset"))
containing multiple copies of equivalent elements[.](#1.sentence-2)
The semantics of the set operations are generalized to multisets
in a standard way by defining set_union to contain the maximum number of occurrences of every element,set_intersection to contain the minimum, and so on[.](#1.sentence-3)

161
cppdraft/alg/shift.md Normal file
View File

@@ -0,0 +1,161 @@
[alg.shift]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.shift)
### 26.7.14 Shift [alg.shift]
[🔗](#lib:shift_left)
`template<class ForwardIterator>
constexpr ForwardIterator
shift_left(ForwardIterator first, ForwardIterator last,
typename iterator_traits<ForwardIterator>::difference_type n);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator
shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
typename iterator_traits<ForwardIterator>::difference_type n);
template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S>
constexpr subrange<I> ranges::shift_left(I first, S last, iter_difference_t<I> n);
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_subrange_t<R> ranges::shift_left(R&& r, range_difference_t<R> n);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
subrange<I>
ranges::shift_left(Ep&& exec, I first, S last, iter_difference_t<I> n);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_subrange_t<R>
ranges::shift_left(Ep&& exec, R&& r, range_difference_t<R> n);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8554)
*Preconditions*: n >= 0 is true[.](#1.sentence-1)
For the overloads in namespace std,
the type of *first meets the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8560)
*Effects*: If n == 0 or n >= last - first, does nothing[.](#2.sentence-1)
Otherwise, moves the element
from position first + n + i into position first + i for each non-negative integer i < (last - first) - n[.](#2.sentence-2)
For the non-parallel algorithm overloads,
does so in order starting
from i = 0 and proceeding to i = (last - first) - n - 1[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8571)
*Returns*: Let *NEW_LAST* be first + (last - first - n) if n < last - first,
otherwise first[.](#3.sentence-1)
Returns:
- [(3.1)](#3.1)
*NEW_LAST* for the overloads in namespace std[.](#3.1.sentence-1)
- [(3.2)](#3.2)
{first, *NEW_LAST*} for the overloads in namespace ranges[.](#3.2.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8585)
*Complexity*: At most (last - first) - n assignments[.](#4.sentence-1)
[🔗](#lib:shift_right)
`template<class ForwardIterator>
constexpr ForwardIterator
shift_right(ForwardIterator first, ForwardIterator last,
typename iterator_traits<ForwardIterator>::difference_type n);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator
shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
typename iterator_traits<ForwardIterator>::difference_type n);
template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S>
constexpr subrange<I> ranges::shift_right(I first, S last, iter_difference_t<I> n);
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_subrange_t<R> ranges::shift_right(R&& r, range_difference_t<R> n);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
subrange<I>
ranges::shift_right(Ep&& exec, I first, S last, iter_difference_t<I> n);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_subrange_t<R>
ranges::shift_right(Ep&& exec, R&& r, range_difference_t<R> n);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8618)
*Preconditions*: n >= 0 is true[.](#5.sentence-1)
For the overloads in namespace std,
the type of *first meets the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements,
and ForwardIterator meets
the [*Cpp17BidirectionalIterator*](bidirectional.iterators#:Cpp17BidirectionalIterator "24.3.5.6Bidirectional iterators[bidirectional.iterators]") requirements ([[bidirectional.iterators]](bidirectional.iterators "24.3.5.6Bidirectional iterators")) or
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8627)
*Effects*: If n == 0 or n >= last - first, does nothing[.](#6.sentence-1)
Otherwise, moves the element
from position first + i into position first + n + i for each non-negative integer i < (last - first) - n[.](#6.sentence-2)
Does so in order starting
from i = (last - first) - n - 1 and proceeding to i = 0 if
- [(6.1)](#6.1)
for the non-parallel algorithm overload in namespace std,ForwardIterator meets the *Cpp17BidirectionalIterator* requirements,
- [(6.2)](#6.2)
for the non-parallel algorithm overloads in namespace ranges,I models [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]")[.](#6.sentence-3)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8644)
*Returns*: Let *NEW_FIRST* be first + n if n < last - first,
otherwise last[.](#7.sentence-1)
Returns:
- [(7.1)](#7.1)
*NEW_FIRST* for the overloads in namespace std[.](#7.1.sentence-1)
- [(7.2)](#7.2)
{*NEW_FIRST*, last} for the overloads in namespace ranges[.](#7.2.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8657)
*Complexity*: At most (last - first) - n assignments or swaps[.](#8.sentence-1)

559
cppdraft/alg/sort.md Normal file
View File

@@ -0,0 +1,559 @@
[alg.sort]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.sort)
### 26.8.2 Sorting [alg.sort]
#### [26.8.2.1](#sort) sort [[sort]](sort)
[🔗](#lib:sort)
`template<class RandomAccessIterator>
constexpr void sort(RandomAccessIterator first, RandomAccessIterator last);
template<class ExecutionPolicy, class RandomAccessIterator>
void sort(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void sort(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
void sort(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I
ranges::sort(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::sort(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
I ranges::sort(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
borrowed_iterator_t<R> ranges::sort(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[1](#sort-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8795)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#sort-1.sentence-1)
[2](#sort-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8800)
*Preconditions*: For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#sort-2.sentence-1)
[3](#sort-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8809)
*Effects*: Sorts the elements in the range [first, last)
with respect to comp and proj[.](#sort-3.sentence-1)
[4](#sort-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8814)
*Returns*: last for the overloads in namespace ranges[.](#sort-4.sentence-1)
[5](#sort-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8818)
*Complexity*: Let N be last - first[.](#sort-5.sentence-1)
O(NlogN) comparisons and projections[.](#sort-5.sentence-2)
#### [26.8.2.2](#stable.sort) stable_sort [[stable.sort]](stable.sort)
[🔗](#lib:stable_sort)
`template<class RandomAccessIterator>
constexpr void stable_sort(RandomAccessIterator first, RandomAccessIterator last);
template<class ExecutionPolicy, class RandomAccessIterator>
void stable_sort(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void stable_sort(RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
void stable_sort(ExecutionPolicy&& exec,
RandomAccessIterator first, RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I ranges::stable_sort(I first, S last, Comp comp = {}, Proj proj = {});
template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::stable_sort(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
I ranges::stable_sort(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
borrowed_iterator_t<R>
ranges::stable_sort(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[1](#stable.sort-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8863)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#stable.sort-1.sentence-1)
[2](#stable.sort-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8868)
*Preconditions*: For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#stable.sort-2.sentence-1)
[3](#stable.sort-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8877)
*Effects*: Sorts the elements in the range [first, last)
with respect to comp and proj[.](#stable.sort-3.sentence-1)
[4](#stable.sort-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8882)
*Returns*: last for the overloads in namespace ranges[.](#stable.sort-4.sentence-1)
[5](#stable.sort-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8886)
*Complexity*: Let N be last - first[.](#stable.sort-5.sentence-1)
If enough extra memory is available, Nlog(N) comparisons[.](#stable.sort-5.sentence-2)
Otherwise, at most Nlog2(N) comparisons[.](#stable.sort-5.sentence-3)
In either case, twice as many projections as the number of comparisons[.](#stable.sort-5.sentence-4)
[6](#stable.sort-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8893)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#stable.sort-6.sentence-1)
#### [26.8.2.3](#partial.sort) partial_sort [[partial.sort]](partial.sort)
[🔗](#lib:partial_sort)
`template<class RandomAccessIterator>
constexpr void partial_sort(RandomAccessIterator first,
RandomAccessIterator middle,
RandomAccessIterator last);
template<class ExecutionPolicy, class RandomAccessIterator>
void partial_sort(ExecutionPolicy&& exec,
RandomAccessIterator first,
RandomAccessIterator middle,
RandomAccessIterator last);
template<class RandomAccessIterator, class Compare>
constexpr void partial_sort(RandomAccessIterator first,
RandomAccessIterator middle,
RandomAccessIterator last,
Compare comp);
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
void partial_sort(ExecutionPolicy&& exec,
RandomAccessIterator first,
RandomAccessIterator middle,
RandomAccessIterator last,
Compare comp);
template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
constexpr I
ranges::partial_sort(I first, I middle, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I, Comp, Proj>
I ranges::partial_sort(Ep&& exec, I first, I middle, S last, Comp comp = {}, Proj proj = {});
`
[1](#partial.sort-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8936)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#partial.sort-1.sentence-1)
[2](#partial.sort-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8941)
*Preconditions*: [first, middle) and [middle, last) are valid ranges[.](#partial.sort-2.sentence-1)
For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) and
the type of *first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#partial.sort-2.sentence-2)
[3](#partial.sort-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8951)
*Effects*: Places the first middle - first elements
from the range [first, last)
as sorted with respect to comp and proj into the range [first, middle)[.](#partial.sort-3.sentence-1)
The rest of the elements in the range [middle, last)
are placed in an unspecified order[.](#partial.sort-3.sentence-2)
[4](#partial.sort-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8961)
*Returns*: last for the overload in namespace ranges[.](#partial.sort-4.sentence-1)
[5](#partial.sort-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8965)
*Complexity*: Approximately (last - first) * log(middle - first) comparisons, and
twice as many projections[.](#partial.sort-5.sentence-1)
[🔗](#partial.sort-itemdecl:2)
`template<[random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R, class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
constexpr borrowed_iterator_t<R>
ranges::partial_sort(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});
`
[6](#partial.sort-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8979)
*Effects*: Equivalent to:return ranges::partial_sort(ranges::begin(r), middle, ranges::end(r), comp, proj);
[🔗](#partial.sort-itemdecl:3)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R,
class Comp = ranges::less, class Proj = identity>
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R>, Comp, Proj>
borrowed_iterator_t<R>
ranges::partial_sort(Ep&& exec, R&& r, iterator_t<R> middle, Comp comp = {},
Proj proj = {});
`
[7](#partial.sort-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8997)
*Effects*: Equivalent to:return ranges::partial_sort(std::forward<Ep>(exec), ranges::begin(r), middle,
ranges::end(r), comp, proj);
#### [26.8.2.4](#partial.sort.copy) partial_sort_copy [[partial.sort.copy]](partial.sort.copy)
[🔗](#lib:partial_sort_copy)
`template<class InputIterator, class RandomAccessIterator>
constexpr RandomAccessIterator
partial_sort_copy(InputIterator first, InputIterator last,
RandomAccessIterator result_first,
RandomAccessIterator result_last);
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator>
RandomAccessIterator
partial_sort_copy(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
RandomAccessIterator result_first,
RandomAccessIterator result_last);
template<class InputIterator, class RandomAccessIterator,
class Compare>
constexpr RandomAccessIterator
partial_sort_copy(InputIterator first, InputIterator last,
RandomAccessIterator result_first,
RandomAccessIterator result_last,
Compare comp);
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator,
class Compare>
RandomAccessIterator
partial_sort_copy(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
RandomAccessIterator result_first,
RandomAccessIterator result_last,
Compare comp);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I1, I2> && [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I2, Comp, Proj2> &&
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<Comp, projected<I1, Proj1>, projected<I2, Proj2>>
constexpr ranges::partial_sort_copy_result<I1, I2>
ranges::partial_sort_copy(I1 first, S1 last, I2 result_first, S2 result_last,
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [random_access_range](range.refinements#concept:random_access_range "25.4.6Other range refinements[range.refinements]") R2, class Comp = ranges::less,
class Proj1 = identity, class Proj2 = identity>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R1>, iterator_t<R2>> &&
[sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R2>, Comp, Proj2> &&
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<Comp, projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>>
constexpr ranges::partial_sort_copy_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
ranges::partial_sort_copy(R1&& r, R2&& result_r, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I1, I2> && [sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<I2, Comp, Proj2> &&
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<Comp, projected<I1, Proj1>, projected<I2, Proj2>>
ranges::partial_sort_copy_result<I1, I2>
ranges::partial_sort_copy(Ep&& exec, I1 first, S1 last, I2 result_first, S2 result_last,
Comp comp = {}, Proj1 proj1 = {},
Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R1>, iterator_t<R2>> &&
[sortable](alg.req.sortable#concept:sortable "24.3.7.8Concept sortable[alg.req.sortable]")<iterator_t<R2>, Comp, Proj2> &&
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<Comp, projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>>
ranges::partial_sort_copy_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
ranges::partial_sort_copy(Ep&& exec, R1&& r, R2&& result_r, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#partial.sort.copy-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9076)
Let N be min(last - first, result_last - result_first)[.](#partial.sort.copy-1.sentence-1)
Let comp be less{}, andproj1 and proj2 be identity{} for the overloads with no parameters by those names[.](#partial.sort.copy-1.sentence-2)
[2](#partial.sort.copy-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9082)
*Mandates*: For the overloads in namespace std,
the expression *first is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to result_first[.](#partial.sort.copy-2.sentence-1)
[3](#partial.sort.copy-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9088)
*Preconditions*: For the overloads in namespace std,RandomAccessIterator meets
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3Swappable requirements[swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")),
the type of *result_first meets
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) requirements[.](#partial.sort.copy-3.sentence-1)
[4](#partial.sort.copy-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9097)
For iterators a1 and b1 in [first, last), and
iterators x2 and y2 in [result_first, result_last),
after evaluating the assignment *y2 = *b1, let E be the value ofbool(invoke(comp, invoke(proj1, *a1), invoke(proj2, *y2))).
Then, after evaluating the assignment *x2 = *a1, E is equal tobool(invoke(comp, invoke(proj2, *x2), invoke(proj2, *y2))).
[*Note [1](#partial.sort.copy-note-1)*:
Writing a value from the input range into the output range does not affect
how it is ordered by comp and proj1 or proj2[.](#partial.sort.copy-4.sentence-2)
— *end note*]
[5](#partial.sort.copy-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9113)
*Effects*: Places the first N elements
as sorted with respect to comp and proj2 into the range [result_first, result_first + N)[.](#partial.sort.copy-5.sentence-1)
[6](#partial.sort.copy-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9119)
*Returns*:
- [(6.1)](#partial.sort.copy-6.1)
result_first + N for the overloads in namespace std[.](#partial.sort.copy-6.1.sentence-1)
- [(6.2)](#partial.sort.copy-6.2)
{last, result_first + N} for
the overloads in namespace ranges[.](#partial.sort.copy-6.2.sentence-1)
[7](#partial.sort.copy-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9129)
*Complexity*: Approximately (last - first) * log N comparisons,
and twice as many projections[.](#partial.sort.copy-7.sentence-1)
#### [26.8.2.5](#is.sorted) is_sorted [[is.sorted]](is.sorted)
[🔗](#lib:is_sorted)
`template<class ForwardIterator>
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last);
`
[1](#is.sorted-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9144)
*Effects*: Equivalent to: return is_sorted_until(first, last) == last;
[🔗](#lib:is_sorted_)
`template<class ExecutionPolicy, class ForwardIterator>
bool is_sorted(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last);
`
[2](#is.sorted-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9157)
*Effects*: Equivalent to:return is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last) == last;
[🔗](#lib:is_sorted__)
`template<class ForwardIterator, class Compare>
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last,
Compare comp);
`
[3](#is.sorted-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9173)
*Effects*: Equivalent to: return is_sorted_until(first, last, comp) == last;
[🔗](#lib:is_sorted___)
`template<class ExecutionPolicy, class ForwardIterator, class Compare>
bool is_sorted(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Compare comp);
`
[4](#is.sorted-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9188)
*Effects*: Equivalent to:return is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last;
[🔗](#lib:is_sorted____)
`template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
constexpr bool ranges::is_sorted(I first, S last, Comp comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
constexpr bool ranges::is_sorted(R&& r, Comp comp = {}, Proj proj = {});
`
[5](#is.sorted-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9207)
*Effects*: Equivalent to:return ranges::is_sorted_until(first, last, comp, proj) == last;
[🔗](#is.sorted-itemdecl:6)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
bool ranges::is_sorted(Ep&& exec, I first, S last, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
bool ranges::is_sorted(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[6](#is.sorted-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9224)
*Effects*: Equivalent to:return ranges::is_sorted_until(std::forward<Ep>(exec), first, last, comp, proj) == last;
[🔗](#lib:is_sorted_until)
`template<class ForwardIterator>
constexpr ForwardIterator
is_sorted_until(ForwardIterator first, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator
is_sorted_until(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class Compare>
constexpr ForwardIterator
is_sorted_until(ForwardIterator first, ForwardIterator last,
Compare comp);
template<class ExecutionPolicy, class ForwardIterator, class Compare>
ForwardIterator
is_sorted_until(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
Compare comp);
template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
constexpr I ranges::is_sorted_until(I first, S last, Comp comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
constexpr borrowed_iterator_t<R>
ranges::is_sorted_until(R&& r, Comp comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Comp = ranges::less>
I ranges::is_sorted_until(Ep&& exec, I first, S last, Comp comp = {},
Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Comp = ranges::less>
borrowed_iterator_t<R>
ranges::is_sorted_until(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});
`
[7](#is.sorted-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9272)
Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#is.sorted-7.sentence-1)
[8](#is.sorted-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9277)
*Returns*: The last iterator i in [first, last]
for which the range [first, i)
is sorted with respect to comp and proj[.](#is.sorted-8.sentence-1)
[9](#is.sorted-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L9283)
*Complexity*: Linear[.](#is.sorted-9.sentence-1)

3654
cppdraft/alg/sorting.md Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,116 @@
[alg.sorting.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#general)
### 26.8.1 General [alg.sorting.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8666)
The operations in [[alg.sorting]](alg.sorting "26.8Sorting and related operations") defined directly in namespace std have two versions:
one that takes a function object of type Compare and
one that uses an operator<[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8672)
Compare is a function object type ([[function.objects]](function.objects "22.10Function objects"))
that meets the requirements for a template parameter
named BinaryPredicate ([[algorithms.requirements]](algorithms.requirements "26.2Algorithms requirements"))[.](#2.sentence-1)
The return value of the function call operation
applied to an object of type Compare,
when converted to bool,
yields true if the first argument of the call is less than the second, andfalse otherwise[.](#2.sentence-2)
Compare comp is used throughout
for algorithms assuming an ordering relation[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8685)
For all algorithms that take Compare,
there is a version that uses operator< instead[.](#3.sentence-1)
That is, comp(*i, *j) != false defaults to *i < *j != false[.](#3.sentence-2)
For algorithms other than those described in [[alg.binary.search]](alg.binary.search "26.8.4Binary search"),comp shall induce a strict weak ordering on the values[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8692)
The term [*strict*](#def:strict) refers to the requirement
of an irreflexive relation (!comp(x, x) for all x),
and the term [*weak*](#def:weak) to requirements
that are not as strong as those for a total ordering,
but stronger than those for a partial ordering[.](#4.sentence-1)
If we define equiv(a, b) as !comp(a, b) && !comp(b, a),
then the requirements are that comp and equiv both be transitive relations:
- [(4.1)](#4.1)
comp(a, b) && comp(b, c) implies comp(a, c)
- [(4.2)](#4.2)
equiv(a, b) && equiv(b, c) implies equiv(a, c)
[*Note [1](#note-1)*:
Under these conditions, it can be shown that
- [(4.3)](#4.3)
equiv is an equivalence relation,
- [(4.4)](#4.4)
comp induces a well-defined relation
on the equivalence classes determined by equiv, and
- [(4.5)](#4.5)
the induced relation is a strict total ordering[.](#4.sentence-2)
— *end note*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8718)
A sequence is [*sorted with respect to a comp and proj*](#def:sorted_with_respect_to_a_comp_and_proj) for a comparator and projection comp and proj if for every iterator i pointing to the sequence and
every non-negative integer n such that i + n is a valid iterator
pointing to an element of the sequence,bool(invoke(comp, invoke(proj, *(i + n)), invoke(proj, *i))) is false[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8731)
A sequence is [*sorted with respect to a comparator comp*](#def:sorted_with_respect_to_a_comparator_comp) for a comparator comp if it is sorted with respect tocomp and identity{} (the identity projection)[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8738)
A sequence [start, finish) is[*partitioned with respect to an expression*](#def:partitioned_with_respect_to_an_expression) f(e) if there exists an integer n such that for all 0 <= i < (finish - start),f(*(start + i)) is true if and only if i < n[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8745)
In the descriptions of the functions that deal with ordering relationships
we frequently use a notion of equivalence to describe concepts
such as stability[.](#8.sentence-1)
The equivalence to which we refer is not necessarily an operator==,
but an equivalence relation induced by the strict weak ordering[.](#8.sentence-2)
That is, two elements a and b are considered equivalent
if and only if !(a < b) && !(b < a)[.](#8.sentence-3)

View File

@@ -0,0 +1,51 @@
[alg.starts.with]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.6 Non-modifying sequence operations [[alg.nonmodifying]](alg.nonmodifying#alg.starts.with)
### 26.6.16 Starts with [alg.starts.with]
[🔗](#lib:starts_with)
`template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
constexpr bool ranges::starts_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity,
class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
constexpr bool ranges::starts_with(R1&& r1, R2&& r2, Pred pred = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6045)
*Returns*: ranges::mismatch(std::move(first1), last1, std::move(first2), last2,
pred, proj1, proj2).in2 == last2
[🔗](#itemdecl:2)
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2>
bool ranges::starts_with(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2, class Pred = ranges::equal_to,
class Proj1 = identity, class Proj2 = identity>
requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
bool ranges::starts_with(Ep&& exec, R1&& r1, R2&& r2,
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6069)
*Returns*: ranges::mismatch(std::forward<Ep>(exec), std::move(first1), last1, std::move(first2),
last2, pred, proj1, proj2).in2 == last2

117
cppdraft/alg/swap.md Normal file
View File

@@ -0,0 +1,117 @@
[alg.swap]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.swap)
### 26.7.3 Swap [alg.swap]
[🔗](#lib:swap_ranges)
`template<class ForwardIterator1, class ForwardIterator2>
constexpr ForwardIterator2
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
swap_ranges(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2>
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")<I1, I2>
constexpr ranges::swap_ranges_result<I1, I2>
ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2>
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")<iterator_t<R1>, iterator_t<R2>>
constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
ranges::swap_ranges(R1&& r1, R2&& r2);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2>
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")<I1, I2>
ranges::swap_ranges_result<I1, I2>
ranges::swap_ranges(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2>
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4Concept indirectly_­swappable[alg.req.ind.swap]")<iterator_t<R1>, iterator_t<R2>>
ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
ranges::swap_ranges(Ep&& exec, R1&& r1, R2&& r2);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6886)
Let:
- [(1.1)](#1.1)
last2 be first2 + (last1 - first1) for the overloads in namespace std with no parameter named last2;
- [(1.2)](#1.2)
M be min(last1 - first1, last2 - first2)[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6896)
*Preconditions*: The two ranges [first1, last1) and [first2, last2)
do not overlap[.](#2.sentence-1)
For the overloads in namespace std,*(first1 + n) is swappable with ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))*(first2 + n)[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6904)
*Effects*: For each non-negative integer n<M performs:
- [(3.1)](#3.1)
swap(*(first1 + n), *(first2 + n)) for the overloads in namespace std;
- [(3.2)](#3.2)
ranges::iter_swap(first1 + n, first2 + n) for the overloads in namespace ranges[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6916)
*Returns*:
- [(4.1)](#4.1)
last2 for the overloads in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{first1 + M, first2 + M} for the overloads in namespace ranges[.](#4.2.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6927)
*Complexity*: Exactly M swaps[.](#5.sentence-1)
[🔗](#lib:iter_swap)
`template<class ForwardIterator1, class ForwardIterator2>
constexpr void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6939)
*Preconditions*: a and b are dereferenceable[.](#6.sentence-1)
*a is
swappable with ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements")) *b[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6944)
*Effects*: As if by swap(*a, *b)[.](#7.sentence-1)

58
cppdraft/alg/three/way.md Normal file
View File

@@ -0,0 +1,58 @@
[alg.three.way]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.three.way)
### 26.8.12 Three-way comparison algorithms [alg.three.way]
[🔗](#lib:lexicographical_compare_three_way)
`template<class InputIterator1, class InputIterator2, class Cmp>
constexpr auto
lexicographical_compare_three_way(InputIterator1 b1, InputIterator1 e1,
InputIterator2 b2, InputIterator2 e2,
Cmp comp)
-> decltype(comp(*b1, *b2));
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11857)
Let N be min(e1 - b1, e2 - b2)[.](#1.sentence-1)
Let E(n) be comp(*(b1 + n), *(b2 + n))[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11861)
*Mandates*: decltype(comp(*b1, *b2)) is a comparison category type[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11865)
*Returns*: E(i), where i is the smallest integer in [0, N)
such that E(i) != 0 is true, or(e1 - b1) <=> (e2 - b2) if no such integer exists[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11871)
*Complexity*: At most N applications of comp[.](#4.sentence-1)
[🔗](#lib:lexicographical_compare_three_way_)
`template<class InputIterator1, class InputIterator2>
constexpr auto
lexicographical_compare_three_way(InputIterator1 b1, InputIterator1 e1,
InputIterator2 b2, InputIterator2 e2);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L11885)
*Effects*: Equivalent to:return lexicographical_compare_three_way(b1, e1, b2, e2, compare_three_way());

205
cppdraft/alg/transform.md Normal file
View File

@@ -0,0 +1,205 @@
[alg.transform]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.transform)
### 26.7.4 Transform [alg.transform]
[🔗](#lib:transform)
`template<class InputIterator, class OutputIterator,
class UnaryOperation>
constexpr OutputIterator
transform(InputIterator first1, InputIterator last1,
OutputIterator result, UnaryOperation op);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class UnaryOperation>
ForwardIterator2
transform(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 result, UnaryOperation op);
template<class InputIterator1, class InputIterator2,
class OutputIterator, class BinaryOperation>
constexpr OutputIterator
transform(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, OutputIterator result,
BinaryOperation binary_op);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class ForwardIterator, class BinaryOperation>
ForwardIterator
transform(ExecutionPolicy&& exec,
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator result,
BinaryOperation binary_op);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F, class Proj = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, indirect_result_t<F&, projected<I, Proj>>>
constexpr ranges::unary_transform_result<I, O>
ranges::transform(I first1, S last1, O result, F op, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F,
class Proj = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
ranges::transform(R&& r, O result, F op, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS,
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F, class Proj = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, indirect_result_t<F&, projected<I, Proj>>>
ranges::unary_transform_result<I, O>
ranges::transform(Ep&& exec, I first1, S last1, O result, OutS result_last,
F op, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR,
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F, class Proj = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<OutR>,
indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
ranges::unary_transform_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::transform(Ep&& exec, R&& r, OutR&& result_r, F op, Proj proj = {});
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2,
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F, class Proj1 = identity,
class Proj2 = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, indirect_result_t<F&, projected<I1, Proj1>,
projected<I2, Proj2>>>
constexpr ranges::binary_transform_result<I1, I2, O>
ranges::transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O,
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>>>
constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
ranges::transform(R1&& r1, R2&& r2, O result,
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> S2,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS,
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F, class Proj1 = identity, class Proj2 = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, indirect_result_t<F&, projected<I1, Proj1>,
projected<I2, Proj2>>>
ranges::binary_transform_result<I1, I2, O>
ranges::transform(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2,
O result, OutS result_last,
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R2,
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]") F,
class Proj1 = identity, class Proj2 = identity>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<OutR>,
indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>>>
ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>,
borrowed_iterator_t<OutR>>
ranges::transform(Ep&& exec, R1&& r1, R2&& r2, OutR&& result_r,
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7043)
Let:
- [(1.1)](#1.1)
last2 be first2 + (last1 - first1) for the overloads in namespace std with parameter first2 but no parameter last2;
- [(1.2)](#1.2)
M be last1 - first1 for unary transforms, or min(last1 - first1, last2 - first2) for binary transforms;
- [(1.3)](#1.3)
result_last be result + M for the overloads with no parameter result_last or result_r;
- [(1.4)](#1.4)
N be min(M, result_last - result);
- [(1.5)](#1.5)
E(i) be
* [(1.5.1)](#1.5.1)
op(*(first1 + (i - result))) for unary transforms defined in namespace std;
* [(1.5.2)](#1.5.2)
binary_op(*(first1 + (i - result)), *(first2 + (i - result))) for binary transforms defined in namespace std;
* [(1.5.3)](#1.5.3)
invoke(op, invoke(proj, *(first1 + (i - result)))) for unary transforms defined in namespace ranges;
* [(1.5.4)](#1.5.4)
invoke(binary_op, invoke(proj1, *(first1 + (i - result))), invoke(proj2, *(first2 + (i - result)))) for binary transforms defined in namespace ranges[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7078)
*Preconditions*: For parallel algorithm overloadsop and binary_op satisfy the requirements
specified in [[algorithms.parallel.user]](algorithms.parallel.user "26.3.2Requirements on user-provided function objects")[.](#2.sentence-1)
op and binary_op do not invalidate iterators or subranges, nor
modify elements in the ranges
- [(2.1)](#2.1)
[first1, first1 + N],
- [(2.2)](#2.2)
[first2, first2 + N], and
- [(2.3)](#2.3)
[result, result + N][.](#2.sentence-2)[203](#footnote-203 "The use of fully closed ranges is intentional.")
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7094)
*Effects*: Assigns through every iterator i in the range [result, result + N)
a new corresponding value equal to E(i)[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7100)
*Returns*:
- [(4.1)](#4.1)
result + N for the overloads defined in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{first1 + N, result + N} for unary transforms defined in namespace ranges[.](#4.2.sentence-1)
- [(4.3)](#4.3)
{first1 + N, first2 + N, result + N} for binary transforms defined in namespace ranges[.](#4.3.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7114)
*Complexity*: Exactly N applications of op or binary_op, and
any projections[.](#5.sentence-1)
This requirement also applies to the parallel algorithm overloads[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7120)
*Remarks*: result may be equal to first1 or first2[.](#6.sentence-1)
[203)](#footnote-203)[203)](#footnoteref-203)
The use of fully closed ranges is intentional[.](#footnote-203.sentence-1)

278
cppdraft/alg/unique.md Normal file
View File

@@ -0,0 +1,278 @@
[alg.unique]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.unique)
### 26.7.9 Unique [alg.unique]
[🔗](#lib:unique)
`template<class ForwardIterator>
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last);
template<class ExecutionPolicy, class ForwardIterator>
ForwardIterator unique(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last);
template<class ForwardIterator, class BinaryPredicate>
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last,
BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
ForwardIterator unique(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last,
BinaryPredicate pred);
template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to>
constexpr subrange<I> ranges::unique(I first, S last, C comp = {}, Proj proj = {});
template<[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
constexpr borrowed_subrange_t<R>
ranges::unique(R&& r, C comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<I>
subrange<I> ranges::unique(Ep&& exec, I first, S last, C comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6Concept permutable[alg.req.permutable]")<iterator_t<R>>
borrowed_subrange_t<R> ranges::unique(Ep&& exec, R&& r, C comp = {}, Proj proj = {});
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7837)
Let pred be equal_to{} for the overloads with no parameter pred, and
let E be
- [(1.1)](#1.1)
bool(pred(*(i - 1), *i)) for the overloads in namespace std;
- [(1.2)](#1.2)
bool(invoke(comp, invoke(proj, *(i - 1)), invoke(proj, *i))) for the overloads in namespace ranges[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7851)
*Preconditions*: For the overloads in namespace std,pred is an equivalence relation and
the type of *first meets
the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7858)
*Effects*: For a nonempty range, eliminates all but the first element
from every consecutive group of equivalent elements referred to
by the iterator i in the range [first + 1, last)
for which E is true[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7865)
*Returns*: Let j be the end of the resulting range[.](#4.sentence-1)
Returns:
- [(4.1)](#4.1)
j for the overloads in namespace std[.](#4.1.sentence-1)
- [(4.2)](#4.2)
{j, last} for the overloads in namespace ranges[.](#4.2.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7873)
*Complexity*: For nonempty ranges, exactly (last - first) - 1 applications
of the corresponding predicate and
no more than twice as many applications of any projection[.](#5.sentence-1)
[🔗](#lib:unique_copy)
`template<class InputIterator, class OutputIterator>
constexpr OutputIterator
unique_copy(InputIterator first, InputIterator last,
OutputIterator result);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
unique_copy(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result);
template<class InputIterator, class OutputIterator,
class BinaryPredicate>
constexpr OutputIterator
unique_copy(InputIterator first, InputIterator last,
OutputIterator result, BinaryPredicate pred);
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
ForwardIterator2
unique_copy(ExecutionPolicy&& exec,
ForwardIterator1 first, ForwardIterator1 last,
ForwardIterator2 result, BinaryPredicate pred);
template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O> &&
([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I> ||
([input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]")<O> && [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<iter_value_t<I>, iter_value_t<O>>) ||
[indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>)
constexpr ranges::unique_copy_result<I, O>
ranges::unique_copy(I first, S last, O result, C comp = {}, Proj proj = {});
template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") O, class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O> &&
([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<iterator_t<R>> ||
([input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]")<O> && [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<range_value_t<R>, iter_value_t<O>>) ||
[indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly_copyable_storable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, O>)
constexpr ranges::unique_copy_result<borrowed_iterator_t<R>, O>
ranges::unique_copy(R&& r, O result, C comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S,
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> OutS, class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<I, O>
ranges::unique_copy_result<I, O>
ranges::unique_copy(Ep&& exec, I first, S last, O result, OutS result_last,
C comp = {}, Proj proj = {});
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") OutR,
class Proj = identity,
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3Concept indirectly_­copyable[alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>>
ranges::unique_copy_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
ranges::unique_copy(Ep&& exec, R&& r, OutR&& result_r, C comp = {}, Proj proj = {});
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7937)
Let pred be equal_to{} for the overloads
in namespace std with no parameter pred, and
let E(i) be
- [(6.1)](#6.1)
bool(pred(*i, *(i - 1))) for the overloads in namespace std;
- [(6.2)](#6.2)
bool(invoke(comp, invoke(proj, *i), invoke(proj, *(i - 1)))) for the overloads in namespace ranges[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7951)
Let:
- [(7.1)](#7.1)
M be the number of iterators i in the range [first + 1, last)
for which E(i) is false;
- [(7.2)](#7.2)
result_last be result + M + 1 for the overloads with no parameter result_last or result_r;
- [(7.3)](#7.3)
N be min(M+1, result_last - result)[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7964)
*Mandates*: *first is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to result[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7968)
*Preconditions*:
- [(9.1)](#9.1)
The ranges [first, last) and [result, result + N)
do not overlap[.](#9.1.sentence-1)
- [(9.2)](#9.2)
For the overloads in namespace std:
* [(9.2.1)](#9.2.1)
The comparison function is an equivalence relation[.](#9.2.1.sentence-1)
* [(9.2.2)](#9.2.2)
For the overloads with no ExecutionPolicy,
let T be the value type of InputIterator[.](#9.2.2.sentence-1)
If InputIterator models [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") ([[iterator.concept.forward]](iterator.concept.forward "24.3.4.11Concept forward_­iterator")),
then there are no additional requirements for T[.](#9.2.2.sentence-2)
Otherwise, if OutputIterator meets
the [*Cpp17ForwardIterator*](forward.iterators#:Cpp17ForwardIterator "24.3.5.5Forward iterators[forward.iterators]") requirements and
its value type is the same as T,
then T meets
the [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#9.2.2.sentence-3)
Otherwise, T meets both
the *Cpp17CopyConstructible* (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)")) and *Cpp17CopyAssignable* requirements[.](#9.2.2.sentence-4)
[*Note [1](#note-1)*:
For the parallel algorithm overloads in namespace std,
there can be a performance cost
if the value type of ForwardIterator1 does not meet both the*Cpp17CopyConstructible* and *Cpp17CopyAssignable* requirements[.](#9.sentence-2)
For the parallel algorithm overloads in namespace ranges,
there can be a performance cost if iter_value_t<I> does not model [copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]")[.](#9.sentence-3)
— *end note*]
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8005)
*Effects*: Copies only the first element from N consecutive groups of equivalent elements
referred to by the iterator i in the range [first + 1, last)
for which E(i) holds
into the range [result, result + N)[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8012)
*Returns*:
- [(11.1)](#11.1)
result + N for the overloads in namespace std[.](#11.1.sentence-1)
- [(11.2)](#11.2)
{last, result + N} for the overloads in namespace ranges,
if N is equal to M+1[.](#11.2.sentence-1)
- [(11.3)](#11.3)
Otherwise, {j, result_last} for the overloads in namespace ranges,
where j is the iterator in [first + 1, last)
for which E(j) is false and there are exactly N−1 iterators i in [first + 1, j)
for which E(i) is false[.](#11.3.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L8031)
*Complexity*: At most last - first - 1 applications
of the corresponding predicate
and no more than twice as many applications of any projection[.](#12.sentence-1)

View File

@@ -0,0 +1,33 @@
[algorithm.stable]
# 16 Library introduction [[library]](./#library)
## 16.4 Library-wide requirements [[requirements]](requirements#algorithm.stable)
### 16.4.6 Conforming implementations [[conforming]](conforming#algorithm.stable)
#### 16.4.6.8 Requirements for stable algorithms [algorithm.stable]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3742)
When the requirements for an algorithm state that it is “stable” without further elaboration,
it means:
- [(1.1)](#1.1)
For the sort algorithms the relative order of equivalent
elements is preserved[.](#1.1.sentence-1)
- [(1.2)](#1.2)
For the remove and copy algorithms the relative order of
the elements that are not removed is preserved[.](#1.2.sentence-1)
- [(1.3)](#1.3)
For the merge algorithms, for equivalent elements in
the original two ranges, the elements from the first range (preserving their
original order) precede the elements from the second range (preserving their
original order)[.](#1.3.sentence-1)

491
cppdraft/algorithm/syn.md Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,38 @@
[algorithms.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.1 General [algorithms.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6)
This Clause describes components that C++ programs may use to perform
algorithmic operations on <containers> and other sequences[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10)
The following subclauses describe components for
non-modifying sequence operations,
mutating sequence operations,
sorting and related operations,
and algorithms from the C library,
as summarized in Table [85](#tab:algorithms.summary "Table 85: Algorithms library summary")[.](#2.sentence-1)
Table [85](#tab:algorithms.summary) — Algorithms library summary [[tab:algorithms.summary]](./tab:algorithms.summary)
| [🔗](#tab:algorithms.summary-row-1) | **Subclause** | **Header** |
| --- | --- | --- |
| [🔗](#tab:algorithms.summary-row-2)<br>[[algorithms.requirements]](algorithms.requirements "26.2Algorithms requirements") | Algorithms requirements | |
| [🔗](#tab:algorithms.summary-row-3)<br>[[algorithms.parallel]](algorithms.parallel "26.3Parallel algorithms") | Parallel algorithms | <execution> |
| [🔗](#tab:algorithms.summary-row-4)<br>[[algorithms.results]](algorithms.results "26.5Algorithm result types") | Algorithm result types | <algorithm> |
| [🔗](#tab:algorithms.summary-row-5)<br>[[alg.nonmodifying]](alg.nonmodifying "26.6Non-modifying sequence operations") | Non-modifying sequence operations | |
| [🔗](#tab:algorithms.summary-row-6)<br>[[alg.modifying.operations]](alg.modifying.operations "26.7Mutating sequence operations") | Mutating sequence operations | |
| [🔗](#tab:algorithms.summary-row-7)<br>[[alg.sorting]](alg.sorting "26.8Sorting and related operations") | Sorting and related operations | |
| [🔗](#tab:algorithms.summary-row-8)<br>[[numeric.ops]](numeric.ops "26.10Generalized numeric operations") | Generalized numeric operations | <numeric> |
| [🔗](#tab:algorithms.summary-row-9)<br>[[specialized.algorithms]](specialized.algorithms "26.11Specialized <memory> algorithms") | Specialized <memory> algorithms | <memory> |
| [🔗](#tab:algorithms.summary-row-10)<br>[[alg.rand]](alg.rand "26.12Specialized <random> algorithms") | Specialized <random> algorithms | <random> |
| [🔗](#tab:algorithms.summary-row-11)<br>[[alg.c.library]](alg.c.library "26.13C library algorithms") | C library algorithms | <cstdlib> |

View File

@@ -0,0 +1,609 @@
[algorithms.parallel]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.3 Parallel algorithms [algorithms.parallel]
### [26.3.1](#defns) Preamble [[algorithms.parallel.defns]](algorithms.parallel.defns)
[1](#defns-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L287)
Subclause [algorithms.parallel] describes components that C++ programs may use
to perform operations on containers and other sequences in parallel[.](#defns-1.sentence-1)
[2](#defns-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L291)
A [*parallel algorithm*](#def:parallel_algorithm "26.3.1Preamble[algorithms.parallel.defns]") is a function template listed in this document
with a template parameter named ExecutionPolicy or constrained by the following exposition-only concept:template<class Ep>concept [*execution-policy*](#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") = is_execution_policy_v<remove_cvref_t<Ep>>; // *exposition only*
Such a template parameter is termed an [*execution policy template parameter*](#def:template_parameter,execution_policy "26.3.1Preamble[algorithms.parallel.defns]")[.](#defns-2.sentence-2)
[3](#defns-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L301)
A parallel algorithm accesses objects indirectly accessible via its arguments
by invoking the following functions:
- [(3.1)](#defns-3.1)
All operations of the categories of the iterators, sentinels, or mdspan types
that the algorithm is instantiated with[.](#defns-3.1.sentence-1)
- [(3.2)](#defns-3.2)
Operations on those sequence elements that are required by its specification[.](#defns-3.2.sentence-1)
- [(3.3)](#defns-3.3)
User-provided invocable objects
to be applied during the execution of the algorithm,
if required by the specification[.](#defns-3.3.sentence-1)
- [(3.4)](#defns-3.4)
Operations on those invocable objects required by the specification[.](#defns-3.4.sentence-1)
[*Note [1](#defns-note-1)*:
See [[algorithms.requirements]](algorithms.requirements "26.2Algorithms requirements")[.](#defns-3.4.sentence-2)
— *end note*]
These functions are herein called [*element access functions*](#def:element_access_functions "26.3.1Preamble[algorithms.parallel.defns]")[.](#defns-3.sentence-2)
[4](#defns-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L322)
[*Example [1](#defns-example-1)*:
The sort function may invoke the following element access functions:
- [(4.1)](#defns-4.1)
Operations of the random-access iterator of the actual template argument
(as per [[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators")),
as implied by the name of the template parameter RandomAccessIterator[.](#defns-4.1.sentence-1)
- [(4.2)](#defns-4.2)
The swap function on the elements of the sequence
(as per the preconditions specified in [[sort]](sort "26.8.2.1sort"))[.](#defns-4.2.sentence-1)
- [(4.3)](#defns-4.3)
The user-provided Compare function object[.](#defns-4.3.sentence-1)
— *end example*]
[5](#defns-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L338)
A standard library function is [*vectorization-unsafe*](#def:vectorization-unsafe "26.3.1Preamble[algorithms.parallel.defns]") if it is specified to synchronize with another function invocation, or
another function invocation is specified to synchronize with it,
and if it is not a memory allocation or deallocation function
or lock-free atomic modify-write operation ([[atomics.order]](atomics.order "32.5.4Order and consistency"))[.](#defns-5.sentence-1)
[*Note [2](#defns-note-2)*:
Implementations must ensure that internal synchronization
inside standard library functions does not prevent forward progress
when those functions are executed by threads of execution
with weakly parallel forward progress guarantees[.](#defns-5.sentence-2)
— *end note*]
[*Example [2](#defns-example-2)*: int x = 0;
std::mutex m;void f() {int a[] = {1,2};
std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [&](int) { std::lock_guard<mutex> guard(m); // incorrect: lock_guard constructor calls m.lock()++x; });}
The above program may result in two consecutive calls to m.lock() on the same thread of execution (which may deadlock),
because the applications of the function object are not guaranteed
to run on different threads of execution[.](#defns-5.sentence-3)
— *end example*]
### [26.3.2](#user) Requirements on user-provided function objects [[algorithms.parallel.user]](algorithms.parallel.user)
[1](#user-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L370)
Unless otherwise specified,
invocable objects passed into parallel algorithms as objects of a type
denoted by a template parameter namedPredicate,BinaryPredicate,Compare,UnaryOperation,BinaryOperation,BinaryOperation1,BinaryOperation2,BinaryDivideOp, or
constrained by a concept that subsumes [regular_invocable](concept.regularinvocable#concept:regular_invocable "18.7.3Concept regular_­invocable[concept.regularinvocable]") and the operators used by the analogous overloads to these parallel algorithms
that are formed by an invocation
with the specified default predicate or operation (where applicable)
shall not directly or indirectly modify objects via their arguments,
nor shall they rely on the identity of the provided objects[.](#user-1.sentence-1)
### [26.3.3](#exec) Effect of execution policies on algorithm execution [[algorithms.parallel.exec]](algorithms.parallel.exec)
[1](#exec-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L391)
An execution policy template parameter describes
the manner in which the execution of a parallel algorithm may be
parallelized and the manner in which it applies the element access functions[.](#exec-1.sentence-1)
[2](#exec-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L396)
If an object is modified by an element access function,
the algorithm will perform no other unsynchronized accesses to that object[.](#exec-2.sentence-1)
The modifying element access functions are those
which are specified as modifying the object[.](#exec-2.sentence-2)
[*Note [1](#exec-note-1)*:
For example,swap,++,--,@=, and
assignments
modify the object[.](#exec-2.sentence-3)
For the assignment and @= operators, only the left argument is modified[.](#exec-2.sentence-4)
— *end note*]
[3](#exec-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L412)
Unless otherwise stated, implementations may make arbitrary copies of elements
(with type T) from sequences
where is_trivially_copy_constructible_v<T> and is_trivially_destructible_v<T> are true[.](#exec-3.sentence-1)
[*Note [2](#exec-note-2)*:
This implies that user-supplied function objects cannot rely on
object identity of arguments for such input sequences[.](#exec-3.sentence-2)
If object identity of the arguments to these function objects
is important, a wrapping iterator
that returns a non-copied implementation object
such as reference_wrapper<T> ([[refwrap]](refwrap "22.10.6Class template reference_­wrapper")),
or some equivalent solution, can be used[.](#exec-3.sentence-3)
— *end note*]
[4](#exec-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L427)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::sequenced_policy all occur
in the calling thread of execution[.](#exec-4.sentence-1)
[*Note [3](#exec-note-3)*:
The invocations are not interleaved; see [[intro.execution]](intro.execution "6.10.1Sequential execution")[.](#exec-4.sentence-2)
— *end note*]
[5](#exec-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L435)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::unsequenced_policy are permitted to execute in an unordered fashion
in the calling thread of execution,
unsequenced with respect to one another in the calling thread of execution[.](#exec-5.sentence-1)
[*Note [4](#exec-note-4)*:
This means that multiple function object invocations
can be interleaved on a single thread of execution,
which overrides the usual guarantee from [[intro.execution]](intro.execution "6.10.1Sequential execution") that function executions do not overlap with one another[.](#exec-5.sentence-2)
— *end note*]
The behavior of a program is undefined if
it invokes a vectorization-unsafe standard library function
from user code
called from an execution::unsequenced_policy algorithm[.](#exec-5.sentence-3)
[*Note [5](#exec-note-5)*:
Because execution::unsequenced_policy allows
the execution of element access functions
to be interleaved on a single thread of execution,
blocking synchronization, including the use of mutexes, risks deadlock[.](#exec-5.sentence-4)
— *end note*]
[6](#exec-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L458)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::parallel_policy are permitted to execute either
in the invoking thread of execution or
in a thread of execution implicitly created by the library
to support parallel algorithm execution[.](#exec-6.sentence-1)
If the threads of execution created by thread ([[thread.thread.class]](thread.thread.class "32.4.3Class thread"))
or jthread ([[thread.jthread.class]](thread.jthread.class "32.4.4Class jthread"))
provide concurrent forward progress guarantees ([[intro.progress]](intro.progress "6.10.2.3Forward progress")),
then a thread of execution implicitly created by the library will provide
parallel forward progress guarantees;
otherwise, the provided forward progress guarantee isimplementation-defined[.](#exec-6.sentence-2)
Any such invocations executing in the same thread of execution
are indeterminately sequenced with respect to each other[.](#exec-6.sentence-3)
[*Note [6](#exec-note-6)*:
It is the caller's responsibility to ensure
that the invocation does not introduce data races or deadlocks[.](#exec-6.sentence-4)
— *end note*]
[*Example [1](#exec-example-1)*: int a[] = {0,1};
std::vector<int> v;
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int i) { v.push_back(i*2+1); // incorrect: data race});
The program above has a data race because of the unsynchronized access to the
container v[.](#exec-6.sentence-5)
— *end example*]
[*Example [2](#exec-example-2)*: std::atomic<int> x{0};int a[] = {1,2};
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) { x.fetch_add(1, std::memory_order::relaxed); // spin wait for another iteration to change the value of xwhile (x.load(std::memory_order::relaxed) == 1) { } // incorrect: assumes execution order});
The above example depends on the order of execution of the iterations, and
will not terminate if both iterations are executed sequentially
on the same thread of execution[.](#exec-6.sentence-6)
— *end example*]
[*Example [3](#exec-example-3)*: int x = 0;
std::mutex m;int a[] = {1,2};
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) { std::lock_guard<mutex> guard(m); ++x;});
The above example synchronizes access to object x ensuring that it is incremented correctly[.](#exec-6.sentence-7)
— *end example*]
[7](#exec-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L518)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::parallel_unsequenced_policy are
permitted to execute
in an unordered fashion in unspecified threads of execution, and
unsequenced with respect to one another within each thread of execution[.](#exec-7.sentence-1)
These threads of execution are
either the invoking thread of execution
or threads of execution implicitly created by the library;
the latter will provide weakly parallel forward progress guarantees[.](#exec-7.sentence-2)
[*Note [7](#exec-note-7)*:
This means that multiple function object invocations can be interleaved
on a single thread of execution,
which overrides the usual guarantee from [[intro.execution]](intro.execution "6.10.1Sequential execution") that function executions do not overlap with one another[.](#exec-7.sentence-3)
— *end note*]
The behavior of a program is undefined if
it invokes a vectorization-unsafe standard library function
from user code
called from an execution::parallel_unsequenced_policy algorithm[.](#exec-7.sentence-4)
[*Note [8](#exec-note-8)*:
Because execution::parallel_unsequenced_policy allows
the execution of element access functions
to be interleaved on a single thread of execution,
blocking synchronization, including the use of mutexes, risks deadlock[.](#exec-7.sentence-5)
— *end note*]
[8](#exec-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L545)
[*Note [9](#exec-note-9)*:
The semantics of invocation withexecution::unsequenced_policy,execution::parallel_policy, orexecution::parallel_unsequenced_policy allow the implementation to fall back to sequential execution
if the system cannot parallelize an algorithm invocation,
e.g., due to lack of resources[.](#exec-8.sentence-1)
— *end note*]
[9](#exec-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L556)
If an invocation of a parallel algorithm uses threads of execution
implicitly created by the library,
then the invoking thread of execution will either
- [(9.1)](#exec-9.1)
temporarily block
with forward progress guarantee delegation ([[intro.progress]](intro.progress "6.10.2.3Forward progress"))
on the completion of these library-managed threads of execution, or
- [(9.2)](#exec-9.2)
eventually execute an element access function;
the thread of execution will continue to do so until the algorithm is finished[.](#exec-9.sentence-1)
[*Note [10](#exec-note-10)*:
In blocking with forward progress guarantee delegation in this context,
a thread of execution created by the library
is considered to have finished execution
as soon as it has finished the execution
of the particular element access function
that the invoking thread of execution logically depends on[.](#exec-9.sentence-2)
— *end note*]
[10](#exec-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L578)
The semantics of parallel algorithms invoked with an execution policy object ofimplementation-defined type
are implementation-defined[.](#exec-10.sentence-1)
### [26.3.4](#exceptions) Parallel algorithm exceptions [[algorithms.parallel.exceptions]](algorithms.parallel.exceptions)
[1](#exceptions-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L586)
During the execution of a parallel algorithm,
if temporary memory resources are required for parallelization
and none are available, the algorithm throws a bad_alloc exception[.](#exceptions-1.sentence-1)
[2](#exceptions-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L591)
During the execution of a parallel algorithm,
if the invocation of an element access function exits via an uncaught exception,
the behavior is determined by the execution policy[.](#exceptions-2.sentence-1)
### [26.3.5](#overloads) Parallel algorithm overloads [[algorithms.parallel.overloads]](algorithms.parallel.overloads)
[1](#overloads-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L598)
Parallel algorithms are algorithm overloads[.](#overloads-1.sentence-1)
Each parallel algorithm overload
has an additional function parameter P of type T&& as the first function parameter,
where T is the execution policy template parameter[.](#overloads-1.sentence-2)
[*Note [1](#overloads-note-1)*:
Not all algorithms have parallel algorithm overloads[.](#overloads-1.sentence-3)
— *end note*]
[2](#overloads-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L608)
Unless otherwise specified,
the semantics of calling a parallel algorithm overload are identical to
calling the corresponding algorithm overload without the parameter P,
using all but the first argument[.](#overloads-2.sentence-1)
[3](#overloads-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L614)
Unless otherwise specified,
the complexity requirements of a parallel algorithm overload
are relaxed from the complexity requirements of the corresponding overload
without the parameter P as follows:
when the guarantee says “at most *expr*” or
“exactly *expr*”
and does not specify the number of assignments or swaps, and*expr* is not already expressed with O() notation,
the complexity of the algorithm shall be O(expr)[.](#overloads-3.sentence-1)
[4](#overloads-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L626)
A parallel algorithm
with a template parameter named ExecutionPolicy shall not participate in overload resolution unless
that template parameter satisfies [*execution-policy*](#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]")[.](#overloads-4.sentence-1)
### [26.3.6](#execpol) Execution policies [[execpol]](execpol)
#### [26.3.6.1](#execpol.general) General [[execpol.general]](execpol.general)
[1](#execpol.general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L636)
Subclause [[execpol]](#execpol "26.3.6Execution policies") describes classes that are [*execution policy*](#def:execution_policy "26.3.6.1General[execpol.general]") types[.](#execpol.general-1.sentence-1)
An
object of an execution policy type indicates the kinds of parallelism allowed
in the execution of an algorithm and expresses the consequent requirements on
the element access functions[.](#execpol.general-1.sentence-2)
Execution policy types are declared in header [<execution>](execution.syn#header:%3cexecution%3e "33.4Header <execution> synopsis[execution.syn]")[.](#execpol.general-1.sentence-3)
[*Example [1](#execpol.general-example-1)*: using namespace std;
vector<int> v = /* ... */;
// standard sequential sort sort(v.begin(), v.end());
// explicitly sequential sort sort(execution::seq, v.begin(), v.end());
// permitting parallel execution sort(execution::par, v.begin(), v.end());
// permitting vectorization as well sort(execution::par_unseq, v.begin(), v.end()); — *end example*]
[*Note [1](#execpol.general-note-1)*:
Implementations can provide additional execution policies
to those described in this document as extensions
to address parallel architectures that require idiosyncratic
parameters for efficient execution[.](#execpol.general-1.sentence-4)
— *end note*]
#### [26.3.6.2](#execpol.type) Execution policy type trait [[execpol.type]](execpol.type)
[🔗](#lib:is_execution_policy)
`template<class T> struct is_execution_policy;
`
[1](#execpol.type-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L675)
is_execution_policy can be used to detect execution policies for the
purpose of excluding function signatures from otherwise ambiguous overload
resolution participation[.](#execpol.type-1.sentence-1)
[2](#execpol.type-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L680)
is_execution_policy<T> is a *Cpp17UnaryTypeTrait* with a
base characteristic of true_type if T is the type of a standard
or implementation-defined
execution policy, otherwise false_type[.](#execpol.type-2.sentence-1)
[*Note [1](#execpol.type-note-1)*:
This provision reserves the privilege of creating non-standard execution
policies to the library implementation[.](#execpol.type-2.sentence-2)
— *end note*]
[3](#execpol.type-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L691)
The behavior of a program that adds specializations foris_execution_policy is undefined[.](#execpol.type-3.sentence-1)
#### [26.3.6.3](#execpol.seq) Sequenced execution policy [[execpol.seq]](execpol.seq)
[🔗](#lib:execution::sequenced_policy)
`class execution::sequenced_policy { unspecified };
`
[1](#execpol.seq-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L704)
The class execution::sequenced_policy is an execution policy type used
as a unique type to disambiguate parallel algorithm overloading and require
that a parallel algorithm's execution may not be parallelized[.](#execpol.seq-1.sentence-1)
[2](#execpol.seq-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L709)
During the execution of a parallel algorithm with
the execution::sequenced_policy policy,
if the invocation of an element access function exits via an exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2The std::terminate function"))[.](#execpol.seq-2.sentence-1)
#### [26.3.6.4](#execpol.par) Parallel execution policy [[execpol.par]](execpol.par)
[🔗](#lib:execution::parallel_policy)
`class execution::parallel_policy { unspecified };
`
[1](#execpol.par-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L724)
The class execution::parallel_policy is an execution policy type used as
a unique type to disambiguate parallel algorithm overloading and indicate that
a parallel algorithm's execution may be parallelized[.](#execpol.par-1.sentence-1)
[2](#execpol.par-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L729)
During the execution of a parallel algorithm with
the execution::parallel_policy policy,
if the invocation of an element access function exits via an exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2The std::terminate function"))[.](#execpol.par-2.sentence-1)
#### [26.3.6.5](#execpol.parunseq) Parallel and unsequenced execution policy [[execpol.parunseq]](execpol.parunseq)
[🔗](#lib:execution::parallel_unsequenced_policy)
`class execution::parallel_unsequenced_policy { unspecified };
`
[1](#execpol.parunseq-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L744)
The class execution::parallel_unsequenced_policy is an execution policy type
used as a unique type to disambiguate parallel algorithm overloading and
indicate that a parallel algorithm's execution may be parallelized and
vectorized[.](#execpol.parunseq-1.sentence-1)
[2](#execpol.parunseq-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L750)
During the execution of a parallel algorithm with
the execution::parallel_unsequenced_policy policy,
if the invocation of an element access function exits via an exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2The std::terminate function"))[.](#execpol.parunseq-2.sentence-1)
#### [26.3.6.6](#execpol.unseq) Unsequenced execution policy [[execpol.unseq]](execpol.unseq)
[🔗](#lib:execution::unsequenced_policy)
`class execution::unsequenced_policy { unspecified };
`
[1](#execpol.unseq-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L765)
The class unsequenced_policy is an execution policy type
used as a unique type to disambiguate parallel algorithm overloading and
indicate that a parallel algorithm's execution may be vectorized,
e.g., executed on a single thread using instructions
that operate on multiple data items[.](#execpol.unseq-1.sentence-1)
[2](#execpol.unseq-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L772)
During the execution of a parallel algorithm with
the execution::unsequenced_policy policy,
if the invocation of an element access function exits via an exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2The std::terminate function"))[.](#execpol.unseq-2.sentence-1)
#### [26.3.6.7](#execpol.objects) Execution policy objects [[execpol.objects]](execpol.objects)
[🔗](#lib:seq)
`inline constexpr execution::sequenced_policy execution::seq{ unspecified };
inline constexpr execution::parallel_policy execution::par{ unspecified };
inline constexpr execution::parallel_unsequenced_policy execution::par_unseq{ unspecified };
inline constexpr execution::unsequenced_policy execution::unseq{ unspecified };
`
[1](#execpol.objects-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L795)
The header [<execution>](execution.syn#header:%3cexecution%3e "33.4Header <execution> synopsis[execution.syn]") declares global objects associated with each type of execution policy[.](#execpol.objects-1.sentence-1)

View File

@@ -0,0 +1,107 @@
[algorithms.parallel.defns]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.3 Parallel algorithms [[algorithms.parallel]](algorithms.parallel#defns)
### 26.3.1 Preamble [algorithms.parallel.defns]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L287)
Subclause [[algorithms.parallel]](algorithms.parallel "26.3Parallel algorithms") describes components that C++ programs may use
to perform operations on containers and other sequences in parallel[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L291)
A [*parallel algorithm*](#def:parallel_algorithm "26.3.1Preamble[algorithms.parallel.defns]") is a function template listed in this document
with a template parameter named ExecutionPolicy or constrained by the following exposition-only concept:template<class Ep>concept [*execution-policy*](#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") = is_execution_policy_v<remove_cvref_t<Ep>>; // *exposition only*
Such a template parameter is termed an [*execution policy template parameter*](#def:template_parameter,execution_policy "26.3.1Preamble[algorithms.parallel.defns]")[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L301)
A parallel algorithm accesses objects indirectly accessible via its arguments
by invoking the following functions:
- [(3.1)](#3.1)
All operations of the categories of the iterators, sentinels, or mdspan types
that the algorithm is instantiated with[.](#3.1.sentence-1)
- [(3.2)](#3.2)
Operations on those sequence elements that are required by its specification[.](#3.2.sentence-1)
- [(3.3)](#3.3)
User-provided invocable objects
to be applied during the execution of the algorithm,
if required by the specification[.](#3.3.sentence-1)
- [(3.4)](#3.4)
Operations on those invocable objects required by the specification[.](#3.4.sentence-1)
[*Note [1](#note-1)*:
See [[algorithms.requirements]](algorithms.requirements "26.2Algorithms requirements")[.](#3.4.sentence-2)
— *end note*]
These functions are herein called [*element access functions*](#def:element_access_functions "26.3.1Preamble[algorithms.parallel.defns]")[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L322)
[*Example [1](#example-1)*:
The sort function may invoke the following element access functions:
- [(4.1)](#4.1)
Operations of the random-access iterator of the actual template argument
(as per [[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators")),
as implied by the name of the template parameter RandomAccessIterator[.](#4.1.sentence-1)
- [(4.2)](#4.2)
The swap function on the elements of the sequence
(as per the preconditions specified in [[sort]](sort "26.8.2.1sort"))[.](#4.2.sentence-1)
- [(4.3)](#4.3)
The user-provided Compare function object[.](#4.3.sentence-1)
— *end example*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L338)
A standard library function is [*vectorization-unsafe*](#def:vectorization-unsafe "26.3.1Preamble[algorithms.parallel.defns]") if it is specified to synchronize with another function invocation, or
another function invocation is specified to synchronize with it,
and if it is not a memory allocation or deallocation function
or lock-free atomic modify-write operation ([[atomics.order]](atomics.order "32.5.4Order and consistency"))[.](#5.sentence-1)
[*Note [2](#note-2)*:
Implementations must ensure that internal synchronization
inside standard library functions does not prevent forward progress
when those functions are executed by threads of execution
with weakly parallel forward progress guarantees[.](#5.sentence-2)
— *end note*]
[*Example [2](#example-2)*: int x = 0;
std::mutex m;void f() {int a[] = {1,2};
std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [&](int) { std::lock_guard<mutex> guard(m); // incorrect: lock_guard constructor calls m.lock()++x; });}
The above program may result in two consecutive calls to m.lock() on the same thread of execution (which may deadlock),
because the applications of the function object are not guaranteed
to run on different threads of execution[.](#5.sentence-3)
— *end example*]

View File

@@ -0,0 +1,23 @@
[algorithms.parallel.exceptions]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.3 Parallel algorithms [[algorithms.parallel]](algorithms.parallel#exceptions)
### 26.3.4 Parallel algorithm exceptions [algorithms.parallel.exceptions]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L586)
During the execution of a parallel algorithm,
if temporary memory resources are required for parallelization
and none are available, the algorithm throws a bad_alloc exception[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L591)
During the execution of a parallel algorithm,
if the invocation of an element access function exits via an uncaught exception,
the behavior is determined by the execution policy[.](#2.sentence-1)

View File

@@ -0,0 +1,241 @@
[algorithms.parallel.exec]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.3 Parallel algorithms [[algorithms.parallel]](algorithms.parallel#exec)
### 26.3.3 Effect of execution policies on algorithm execution [algorithms.parallel.exec]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L391)
An execution policy template parameter describes
the manner in which the execution of a parallel algorithm may be
parallelized and the manner in which it applies the element access functions[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L396)
If an object is modified by an element access function,
the algorithm will perform no other unsynchronized accesses to that object[.](#2.sentence-1)
The modifying element access functions are those
which are specified as modifying the object[.](#2.sentence-2)
[*Note [1](#note-1)*:
For example,swap,++,--,@=, and
assignments
modify the object[.](#2.sentence-3)
For the assignment and @= operators, only the left argument is modified[.](#2.sentence-4)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L412)
Unless otherwise stated, implementations may make arbitrary copies of elements
(with type T) from sequences
where is_trivially_copy_constructible_v<T> and is_trivially_destructible_v<T> are true[.](#3.sentence-1)
[*Note [2](#note-2)*:
This implies that user-supplied function objects cannot rely on
object identity of arguments for such input sequences[.](#3.sentence-2)
If object identity of the arguments to these function objects
is important, a wrapping iterator
that returns a non-copied implementation object
such as reference_wrapper<T> ([[refwrap]](refwrap "22.10.6Class template reference_­wrapper")),
or some equivalent solution, can be used[.](#3.sentence-3)
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L427)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::sequenced_policy all occur
in the calling thread of execution[.](#4.sentence-1)
[*Note [3](#note-3)*:
The invocations are not interleaved; see [[intro.execution]](intro.execution "6.10.1Sequential execution")[.](#4.sentence-2)
— *end note*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L435)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::unsequenced_policy are permitted to execute in an unordered fashion
in the calling thread of execution,
unsequenced with respect to one another in the calling thread of execution[.](#5.sentence-1)
[*Note [4](#note-4)*:
This means that multiple function object invocations
can be interleaved on a single thread of execution,
which overrides the usual guarantee from [[intro.execution]](intro.execution "6.10.1Sequential execution") that function executions do not overlap with one another[.](#5.sentence-2)
— *end note*]
The behavior of a program is undefined if
it invokes a vectorization-unsafe standard library function
from user code
called from an execution::unsequenced_policy algorithm[.](#5.sentence-3)
[*Note [5](#note-5)*:
Because execution::unsequenced_policy allows
the execution of element access functions
to be interleaved on a single thread of execution,
blocking synchronization, including the use of mutexes, risks deadlock[.](#5.sentence-4)
— *end note*]
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L458)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::parallel_policy are permitted to execute either
in the invoking thread of execution or
in a thread of execution implicitly created by the library
to support parallel algorithm execution[.](#6.sentence-1)
If the threads of execution created by thread ([[thread.thread.class]](thread.thread.class "32.4.3Class thread"))
or jthread ([[thread.jthread.class]](thread.jthread.class "32.4.4Class jthread"))
provide concurrent forward progress guarantees ([[intro.progress]](intro.progress "6.10.2.3Forward progress")),
then a thread of execution implicitly created by the library will provide
parallel forward progress guarantees;
otherwise, the provided forward progress guarantee isimplementation-defined[.](#6.sentence-2)
Any such invocations executing in the same thread of execution
are indeterminately sequenced with respect to each other[.](#6.sentence-3)
[*Note [6](#note-6)*:
It is the caller's responsibility to ensure
that the invocation does not introduce data races or deadlocks[.](#6.sentence-4)
— *end note*]
[*Example [1](#example-1)*: int a[] = {0,1};
std::vector<int> v;
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int i) { v.push_back(i*2+1); // incorrect: data race});
The program above has a data race because of the unsynchronized access to the
container v[.](#6.sentence-5)
— *end example*]
[*Example [2](#example-2)*: std::atomic<int> x{0};int a[] = {1,2};
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) { x.fetch_add(1, std::memory_order::relaxed); // spin wait for another iteration to change the value of xwhile (x.load(std::memory_order::relaxed) == 1) { } // incorrect: assumes execution order});
The above example depends on the order of execution of the iterations, and
will not terminate if both iterations are executed sequentially
on the same thread of execution[.](#6.sentence-6)
— *end example*]
[*Example [3](#example-3)*: int x = 0;
std::mutex m;int a[] = {1,2};
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) { std::lock_guard<mutex> guard(m); ++x;});
The above example synchronizes access to object x ensuring that it is incremented correctly[.](#6.sentence-7)
— *end example*]
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L518)
The invocations of element access functions in parallel algorithms invoked with
an execution policy object of type execution::parallel_unsequenced_policy are
permitted to execute
in an unordered fashion in unspecified threads of execution, and
unsequenced with respect to one another within each thread of execution[.](#7.sentence-1)
These threads of execution are
either the invoking thread of execution
or threads of execution implicitly created by the library;
the latter will provide weakly parallel forward progress guarantees[.](#7.sentence-2)
[*Note [7](#note-7)*:
This means that multiple function object invocations can be interleaved
on a single thread of execution,
which overrides the usual guarantee from [[intro.execution]](intro.execution "6.10.1Sequential execution") that function executions do not overlap with one another[.](#7.sentence-3)
— *end note*]
The behavior of a program is undefined if
it invokes a vectorization-unsafe standard library function
from user code
called from an execution::parallel_unsequenced_policy algorithm[.](#7.sentence-4)
[*Note [8](#note-8)*:
Because execution::parallel_unsequenced_policy allows
the execution of element access functions
to be interleaved on a single thread of execution,
blocking synchronization, including the use of mutexes, risks deadlock[.](#7.sentence-5)
— *end note*]
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L545)
[*Note [9](#note-9)*:
The semantics of invocation withexecution::unsequenced_policy,execution::parallel_policy, orexecution::parallel_unsequenced_policy allow the implementation to fall back to sequential execution
if the system cannot parallelize an algorithm invocation,
e.g., due to lack of resources[.](#8.sentence-1)
— *end note*]
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L556)
If an invocation of a parallel algorithm uses threads of execution
implicitly created by the library,
then the invoking thread of execution will either
- [(9.1)](#9.1)
temporarily block
with forward progress guarantee delegation ([[intro.progress]](intro.progress "6.10.2.3Forward progress"))
on the completion of these library-managed threads of execution, or
- [(9.2)](#9.2)
eventually execute an element access function;
the thread of execution will continue to do so until the algorithm is finished[.](#9.sentence-1)
[*Note [10](#note-10)*:
In blocking with forward progress guarantee delegation in this context,
a thread of execution created by the library
is considered to have finished execution
as soon as it has finished the execution
of the particular element access function
that the invoking thread of execution logically depends on[.](#9.sentence-2)
— *end note*]
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L578)
The semantics of parallel algorithms invoked with an execution policy object ofimplementation-defined type
are implementation-defined[.](#10.sentence-1)

View File

@@ -0,0 +1,53 @@
[algorithms.parallel.overloads]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.3 Parallel algorithms [[algorithms.parallel]](algorithms.parallel#overloads)
### 26.3.5 Parallel algorithm overloads [algorithms.parallel.overloads]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L598)
Parallel algorithms are algorithm overloads[.](#1.sentence-1)
Each parallel algorithm overload
has an additional function parameter P of type T&& as the first function parameter,
where T is the execution policy template parameter[.](#1.sentence-2)
[*Note [1](#note-1)*:
Not all algorithms have parallel algorithm overloads[.](#1.sentence-3)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L608)
Unless otherwise specified,
the semantics of calling a parallel algorithm overload are identical to
calling the corresponding algorithm overload without the parameter P,
using all but the first argument[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L614)
Unless otherwise specified,
the complexity requirements of a parallel algorithm overload
are relaxed from the complexity requirements of the corresponding overload
without the parameter P as follows:
when the guarantee says “at most *expr*” or
“exactly *expr*”
and does not specify the number of assignments or swaps, and*expr* is not already expressed with O() notation,
the complexity of the algorithm shall be O(expr)[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L626)
A parallel algorithm
with a template parameter named ExecutionPolicy shall not participate in overload resolution unless
that template parameter satisfies [*execution-policy*](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]")[.](#4.sentence-1)

View File

@@ -0,0 +1,20 @@
[algorithms.parallel.user]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.3 Parallel algorithms [[algorithms.parallel]](algorithms.parallel#user)
### 26.3.2 Requirements on user-provided function objects [algorithms.parallel.user]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L370)
Unless otherwise specified,
invocable objects passed into parallel algorithms as objects of a type
denoted by a template parameter namedPredicate,BinaryPredicate,Compare,UnaryOperation,BinaryOperation,BinaryOperation1,BinaryOperation2,BinaryDivideOp, or
constrained by a concept that subsumes [regular_invocable](concept.regularinvocable#concept:regular_invocable "18.7.3Concept regular_­invocable[concept.regularinvocable]") and the operators used by the analogous overloads to these parallel algorithms
that are formed by an invocation
with the specified default predicate or operation (where applicable)
shall not directly or indirectly modify objects via their arguments,
nor shall they rely on the identity of the provided objects[.](#1.sentence-1)

View File

@@ -0,0 +1,271 @@
[algorithms.requirements]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.2 Algorithms requirements [algorithms.requirements]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L32)
All of the algorithms
are separated from the particular implementations of data structures and
are parameterized by iterator types[.](#1.sentence-1)
Because of this, they can work with program-defined data structures,
as long as these data structures have iterator types
satisfying the assumptions on the algorithms[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L40)
The entities defined in the std::ranges namespace in this Clause and
specified as function templates are
algorithm function objects ([[alg.func.obj]](alg.func.obj "16.3.3.4Algorithm function objects"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L45)
For purposes of determining the existence of data races,
algorithms shall not modify objects referenced through an iterator argument
unless the specification requires such modification[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L50)
Throughout this Clause, where the template parameters are not constrained,
the names of template parameters are used to express type requirements[.](#4.sentence-1)
- [(4.1)](#4.1)
If an algorithm's *Effects* element specifies
that a value pointed to by any iterator passed as an argument is modified,
then the type of that argument shall meet
the requirements of a mutable iterator ([[iterator.requirements]](iterator.requirements "24.3Iterator requirements"))[.](#4.1.sentence-1)
- [(4.2)](#4.2)
If an algorithm's template parameter is named InputIterator, InputIterator1, or InputIterator2,
the template argument shall meet the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3Input iterators[input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators"))[.](#4.2.sentence-1)
- [(4.3)](#4.3)
If an algorithm's template parameter is named OutputIterator, OutputIterator1, or OutputIterator2,
the template argument shall meet the [*Cpp17OutputIterator*](output.iterators#:Cpp17OutputIterator "24.3.5.4Output iterators[output.iterators]") requirements ([[output.iterators]](output.iterators "24.3.5.4Output iterators"))[.](#4.3.sentence-1)
- [(4.4)](#4.4)
If an algorithm's template parameter is named ForwardIterator, ForwardIterator1, ForwardIterator2, or NoThrowForwardIterator,
the template argument shall meet the [*Cpp17ForwardIterator*](forward.iterators#:Cpp17ForwardIterator "24.3.5.5Forward iterators[forward.iterators]") requirements ([[forward.iterators]](forward.iterators "24.3.5.5Forward iterators"))
if it is required to be a mutable iterator, or
model [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") ([[iterator.concept.forward]](iterator.concept.forward "24.3.4.11Concept forward_­iterator")) otherwise[.](#4.4.sentence-1)
- [(4.5)](#4.5)
If an algorithm's template parameter is named NoThrowForwardIterator,
the template argument
is also required to have the property that no exceptions are thrown
from increment, assignment, or comparison of, or
indirection through, valid iterators[.](#4.5.sentence-1)
- [(4.6)](#4.6)
If an algorithm's template parameter is named BidirectionalIterator, BidirectionalIterator1, or BidirectionalIterator2,
the template argument shall meet the [*Cpp17BidirectionalIterator*](bidirectional.iterators#:Cpp17BidirectionalIterator "24.3.5.6Bidirectional iterators[bidirectional.iterators]") requirements ([[bidirectional.iterators]](bidirectional.iterators "24.3.5.6Bidirectional iterators"))
if it is required to be a mutable iterator, or model [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") ([[iterator.concept.bidir]](iterator.concept.bidir "24.3.4.12Concept bidirectional_­iterator")) otherwise[.](#4.6.sentence-1)
- [(4.7)](#4.7)
If an algorithm's template parameter is named RandomAccessIterator, RandomAccessIterator1, or RandomAccessIterator2,
the template argument shall meet the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7Random access iterators[random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7Random access iterators"))
if it is required to be a mutable iterator, or model [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") ([[iterator.concept.random.access]](iterator.concept.random.access "24.3.4.13Concept random_­access_­iterator")) otherwise[.](#4.7.sentence-1)
[*Note [1](#note-1)*:
These requirements do not affect iterator arguments that are constrained,
for which iterator category and mutability requirements
are expressed explicitly[.](#4.sentence-2)
— *end note*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L115)
Both in-place and copying versions are provided for certain algorithms[.](#5.sentence-1)[200](#footnote-200 "The decision whether to include a copying version was usually based on complexity considerations. When the cost of doing the operation dominates the cost of copy, the copying version is not included. For example, sort_­copy is not included because the cost of sorting is much more significant, and users can invoke copy followed by sort.")
When such a version is provided for *algorithm* it is called*algorithm_copy*[.](#5.sentence-2)
Algorithms that take predicates end with the suffix _if (which follows the suffix _copy)[.](#5.sentence-3)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L131)
When not otherwise constrained, the Predicate parameter is used
whenever an algorithm expects a function object ([[function.objects]](function.objects "22.10Function objects")) that,
when applied to the result of dereferencing the corresponding iterator,
returns a value testable as true[.](#6.sentence-1)
If an algorithm takes Predicate pred as its argument andfirst as its iterator argument with value type T,
the expression pred(*first) shall be well-formed and
the type decltype(pred(*first)) shall model[*boolean-testable*](concept.booleantestable#concept:boolean-testable "18.5.2Boolean testability[concept.booleantestable]") ([[concept.booleantestable]](concept.booleantestable "18.5.2Boolean testability"))[.](#6.sentence-2)
The function object pred shall not apply any non-constant function
through its argument[.](#6.sentence-3)
Given a glvalue u of type (possibly const) T that designates the same object as *first,pred(u) shall be a valid expression
that is equal to pred(*first)[.](#6.sentence-4)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L148)
When not otherwise constrained, the BinaryPredicate parameter is used
whenever an algorithm expects a function object that, when applied
to the result of dereferencing two corresponding iterators or
to dereferencing an iterator and type T when T is part of the signature,
returns a value testable as true[.](#7.sentence-1)
If an algorithm takes BinaryPredicate binary_pred as its argument andfirst1 and first2 as its iterator arguments
with respective value types T1 and T2,
the expression binary_pred(*first1, *first2) shall be well-formed and
the type decltype(binary_pred(*first1, *first2)) shall model[*boolean-testable*](concept.booleantestable#concept:boolean-testable "18.5.2Boolean testability[concept.booleantestable]")[.](#7.sentence-2)
Unless otherwise specified,BinaryPredicate always takes the first iterator's value_type as its first argument, that is, in those cases when T value is part of the signature,
the expression binary_pred(*first1, value) shall be well-formed and
the type decltype(binary_pred(*first1, value)) shall model[*boolean-testable*](concept.booleantestable#concept:boolean-testable "18.5.2Boolean testability[concept.booleantestable]")[.](#7.sentence-3)
binary_pred shall not apply any non-constant function
through any of its arguments[.](#7.sentence-4)
Given a glvalue u of type (possibly const) T1 that designates the same object as *first1, and
a glvalue v of type (possibly const) T2 that designates the same object as *first2,binary_pred(u, *first2),binary_pred(*first1, v), andbinary_pred(u, v) shall each be a valid expression that is equal tobinary_pred(*first1, *first2), andbinary_pred(u, value) shall be a valid expression that is equal tobinary_pred(*first1, value)[.](#7.sentence-5)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L183)
The parametersUnaryOperation,BinaryOperation,BinaryOperation1,
and BinaryOperation2 are used
whenever an algorithm expects a function object ([[function.objects]](function.objects "22.10Function objects"))[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L192)
[*Note [2](#note-2)*:
Unless otherwise specified, algorithms that take function objects as arguments
can copy those function objects freely[.](#9.sentence-1)
If object identity is important,
a wrapper class that points to a non-copied implementation object
such as reference_wrapper<T> ([[refwrap]](refwrap "22.10.6Class template reference_­wrapper")), or some equivalent solution,
can be used[.](#9.sentence-2)
— *end note*]
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L202)
When the description of an algorithm gives an expression such as*first == value for a condition, the expression
shall evaluate to either true or false in boolean contexts[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L207)
In the description of the algorithms, operator + is used for some of the iterator categories
for which it does not have to be defined[.](#11.sentence-1)
In these cases the semantics of a + n are the same as those ofauto tmp = a;for (; n < 0; ++n) --tmp;for (; n > 0; --n) ++tmp;return tmp;
Similarly, operator - is used
for some combinations of iterators and sentinel types
for which it does not have to be defined[.](#11.sentence-3)
If [a, b) denotes a range,
the semantics of b - a in these cases are the same as those ofiter_difference_t<decltype(a)> n = 0;for (auto tmp = a; tmp != b; ++tmp) ++n;return n; and if [b, a) denotes a range, the same as those ofiter_difference_t<decltype(b)> n = 0;for (auto tmp = b; tmp != a; ++tmp) --n;return n;
For each iterator i and sentinel s produced from a range r,
the semantics of s - i has the same type, value, and value category
as ranges::distance(i, s)[.](#11.sentence-5)
[*Note [3](#note-3)*:
The implementation can use ranges::distance(r) when that produces the same value as ranges::distance(i, s)[.](#11.sentence-6)
This can be more efficient for sized ranges[.](#11.sentence-7)
— *end note*]
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L244)
In the description of the algorithms,
given an iterator a whose difference type is D, and
an expression n of integer-like type other than cv D,
the semantics of a + n and a - n are, respectively,
those of a + D(n) and a - D(n)[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L251)
In the description of algorithm return values,
a sentinel value s denoting the end of a range [i, s)
is sometimes returned where an iterator is expected[.](#13.sentence-1)
In these cases,
the semantics are as if the sentinel is converted into an iterator usingranges::next(i, s)[.](#13.sentence-2)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L259)
Overloads of algorithms that take [range](range.range#concept:range "25.4.2Ranges[range.range]") arguments ([[range.range]](range.range "25.4.2Ranges"))
behave as if they are implemented by
dispatching to the overload in namespace ranges that takes separate iterator and sentinel arguments,
where for each range argument r
- [(14.1)](#14.1)
a corresponding iterator argument is initialized with ranges::begin(r) and
- [(14.2)](#14.2)
a corresponding sentinel argument is initialized with ranges::end(r),
or ranges::next(ranges::begin(r), ranges::end(r)) if the type of r models [forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") and computing ranges::next meets the specified complexity requirements[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L275)
The well-formedness and behavior of a call to an algorithm with
an explicitly-specified template argument list
is unspecified, except where explicitly stated otherwise[.](#15.sentence-1)
[*Note [4](#note-4)*:
Consequently, an implementation can declare an algorithm with
different template parameters than those presented[.](#15.sentence-2)
— *end note*]
[200)](#footnote-200)[200)](#footnoteref-200)
The decision whether to include a copying version was
usually based on complexity considerations[.](#footnote-200.sentence-1)
When the cost of doing the operation dominates the cost of copy,
the copying version is not included[.](#footnote-200.sentence-2)
For example, sort_copy is not included
because the cost of sorting is much more significant,
and users can invoke copy followed by sort[.](#footnote-200.sentence-3)

File diff suppressed because one or more lines are too long

130
cppdraft/alloc/errors.md Normal file
View File

@@ -0,0 +1,130 @@
[alloc.errors]
# 17 Language support library [[support]](./#support)
## 17.6 Dynamic memory management [[support.dynamic]](support.dynamic#alloc.errors)
### 17.6.4 Storage allocation errors [alloc.errors]
#### [17.6.4.1](#bad.alloc) Class bad_alloc [[bad.alloc]](bad.alloc)
[🔗](#lib:bad_alloc,constructor)
namespace std {class bad_alloc : public exception {public:// see [[exception]](exception "17.9.3Class exception") for the specification of the special member functionsconstexpr const char* what() const noexcept override; };}
[1](#bad.alloc-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3031)
The classbad_alloc defines the type of objects thrown as
exceptions by the implementation to report a failure to allocate storage[.](#bad.alloc-1.sentence-1)
[🔗](#lib:what,bad_alloc)
`constexpr const char* what() const noexcept override;
`
[2](#bad.alloc-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3043)
*Returns*: An implementation-defined ntbs[.](#bad.alloc-2.sentence-1)
#### [17.6.4.2](#new.badlength) Class bad_array_new_length [[new.badlength]](new.badlength)
namespace std {class bad_array_new_length : public bad_alloc {public:// see [[exception]](exception "17.9.3Class exception") for the specification of the special member functionsconstexpr const char* what() const noexcept override; };}
[1](#new.badlength-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3062)
The class bad_array_new_length defines the type of objects thrown as
exceptions by the implementation to report an attempt to allocate an array of size
less than zero or
greater than an implementation-defined limit ([[expr.new]](expr.new "7.6.2.8New"))[.](#new.badlength-1.sentence-1)
[🔗](#lib:what,bad_array_new_length)
`constexpr const char* what() const noexcept override;
`
[2](#new.badlength-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3074)
*Returns*: An implementation-defined ntbs[.](#new.badlength-2.sentence-1)
#### [17.6.4.3](#new.handler) Type new_handler [[new.handler]](new.handler)
[🔗](#lib:new_handler)
`using new_handler = void (*)();
`
[1](#new.handler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3087)
The type of a[*handler function*](#def:handler_function) to be called byoperator new() oroperator new[]() ([[new.delete]](new.delete "17.6.3Storage allocation and deallocation")) when they cannot satisfy a request for additional storage[.](#new.handler-1.sentence-1)
[2](#new.handler-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3095)
*Required behavior*: A new_handler shall perform one of the following:
- [(2.1)](#new.handler-2.1)
make more storage available for allocation and then return;
- [(2.2)](#new.handler-2.2)
throw an exception of typebad_alloc or a class derived frombad_alloc;
- [(2.3)](#new.handler-2.3)
terminate execution of the program without returning to the caller[.](#new.handler-2.sentence-1)
#### [17.6.4.4](#set.new.handler) set_new_handler [[set.new.handler]](set.new.handler)
[🔗](#lib:set_new_handler)
`new_handler set_new_handler(new_handler new_p) noexcept;
`
[1](#set.new.handler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3122)
*Effects*: Establishes the function designated by new_p as the currentnew_handler[.](#set.new.handler-1.sentence-1)
[2](#set.new.handler-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3127)
*Returns*: The previous new_handler[.](#set.new.handler-2.sentence-1)
[3](#set.new.handler-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3131)
*Remarks*: The initial new_handler is a null pointer[.](#set.new.handler-3.sentence-1)
#### [17.6.4.5](#get.new.handler) get_new_handler [[get.new.handler]](get.new.handler)
[🔗](#lib:get_new_handler)
`new_handler get_new_handler() noexcept;
`
[1](#get.new.handler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3144)
*Returns*: The current new_handler[.](#get.new.handler-1.sentence-1)
[*Note [1](#get.new.handler-note-1)*:
This can be a null pointer value[.](#get.new.handler-1.sentence-2)
— *end note*]

View File

@@ -0,0 +1,380 @@
[allocator.adaptor]
# 20 Memory management library [[mem]](./#mem)
## 20.6 Class template scoped_allocator_adaptor [allocator.adaptor]
### [20.6.1](#syn) Header <scoped_allocator> synopsis [[allocator.adaptor.syn]](allocator.adaptor.syn)
[🔗](#header:%3cscoped_allocator%3e)
namespace std {// class template scoped_allocator_adaptortemplate<class OuterAlloc, class... InnerAlloc>class scoped_allocator_adaptor; // [[scoped.adaptor.operators]](#scoped.adaptor.operators "20.6.5Operators"), scoped allocator operatorstemplate<class OuterA1, class OuterA2, class... InnerAllocs>bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;}
[1](#syn-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8608)
The class template scoped_allocator_adaptor is an allocator template that
specifies an allocator resource (the outer allocator) to be used by a container (as any
other allocator does) and also specifies an inner allocator resource to be passed to the
constructor of every element within the container[.](#syn-1.sentence-1)
This adaptor is instantiated with one
outer and zero or more inner allocator types[.](#syn-1.sentence-2)
If instantiated with only one allocator
type, the inner allocator becomes the scoped_allocator_adaptor itself, thus
using the same allocator resource for the container and every element within the
container and, if the elements themselves are containers, each of their elements
recursively[.](#syn-1.sentence-3)
If instantiated with more than one allocator, the first allocator is the
outer allocator for use by the container, the second allocator is passed to the
constructors of the container's elements, and, if the elements themselves are
containers, the third allocator is passed to the elements' elements, and so on[.](#syn-1.sentence-4)
If
containers are nested to a depth greater than the number of allocators, the last
allocator is used repeatedly, as in the single-allocator case, for any remaining
recursions[.](#syn-1.sentence-5)
[*Note [1](#syn-note-1)*:
The scoped_allocator_adaptor is derived from the outer
allocator type so it can be substituted for the outer allocator type in most
expressions[.](#syn-1.sentence-6)
— *end note*]
[🔗](#lib:scoped_allocator_adaptor)
namespace std {template<class OuterAlloc, class... InnerAllocs>class scoped_allocator_adaptor : public OuterAlloc {private:using OuterTraits = allocator_traits<OuterAlloc>; // *exposition only* scoped_allocator_adaptor<InnerAllocs...> inner; // *exposition only*public:using outer_allocator_type = OuterAlloc; using inner_allocator_type = *see below*; using value_type = typename OuterTraits::value_type; using size_type = typename OuterTraits::size_type; using difference_type = typename OuterTraits::difference_type; using pointer = typename OuterTraits::pointer; using const_pointer = typename OuterTraits::const_pointer; using void_pointer = typename OuterTraits::void_pointer; using const_void_pointer = typename OuterTraits::const_void_pointer; using propagate_on_container_copy_assignment = *see below*; using propagate_on_container_move_assignment = *see below*; using propagate_on_container_swap = *see below*; using is_always_equal = *see below*; template<class Tp> struct rebind {using other = scoped_allocator_adaptor< OuterTraits::template rebind_alloc<Tp>, InnerAllocs...>; };
scoped_allocator_adaptor(); template<class OuterA2> scoped_allocator_adaptor(OuterA2&& outerAlloc, const InnerAllocs&... innerAllocs) noexcept;
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept; template<class OuterA2> scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept; template<class OuterA2> scoped_allocator_adaptor( scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; ~scoped_allocator_adaptor();
inner_allocator_type& inner_allocator() noexcept; const inner_allocator_type& inner_allocator() const noexcept;
outer_allocator_type& outer_allocator() noexcept; const outer_allocator_type& outer_allocator() const noexcept;
pointer allocate(size_type n);
pointer allocate(size_type n, const_void_pointer hint); void deallocate(pointer p, size_type n);
size_type max_size() const; template<class T, class... Args>void construct(T* p, Args&&... args); template<class T>void destroy(T* p);
scoped_allocator_adaptor select_on_container_copy_construction() const; }; template<class OuterAlloc, class... InnerAllocs> scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)-> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;}
### [20.6.2](#types) Member types [[allocator.adaptor.types]](allocator.adaptor.types)
[🔗](#lib:inner_allocator_type,scoped_allocator_adaptor)
`using inner_allocator_type = see below;
`
[1](#types-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8722)
*Type*: scoped_allocator_adaptor<OuterAlloc> if sizeof...(InnerAllocs) is
zero; otherwise,
scoped_allocator_adaptor<InnerAllocs...>[.](#types-1.sentence-2)
[🔗](#lib:propagate_on_container_copy_assignment,scoped_allocator_adaptor)
`using propagate_on_container_copy_assignment = see below;
`
[2](#types-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8733)
*Type*: true_type ifallocator_traits<A>::propagate_on_container_copy_assignment::value istrue for any A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#types-2.sentence-1)
[🔗](#lib:propagate_on_container_move_assignment,scoped_allocator_adaptor)
`using propagate_on_container_move_assignment = see below;
`
[3](#types-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8746)
*Type*: true_type ifallocator_traits<A>::propagate_on_container_move_assignment::value istrue for any A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#types-3.sentence-1)
[🔗](#lib:propagate_on_container_swap,scoped_allocator_adaptor)
`using propagate_on_container_swap = see below;
`
[4](#types-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8759)
*Type*: true_type ifallocator_traits<A>::propagate_on_container_swap::value istrue for any A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#types-4.sentence-1)
[🔗](#lib:is_always_equal,scoped_allocator_adaptor)
`using is_always_equal = see below;
`
[5](#types-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8772)
*Type*: true_type ifallocator_traits<A>::is_always_equal::value istrue for every A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#types-5.sentence-1)
### [20.6.3](#cnstr) Constructors [[allocator.adaptor.cnstr]](allocator.adaptor.cnstr)
[🔗](#lib:scoped_allocator_adaptor,constructor)
`scoped_allocator_adaptor();
`
[1](#cnstr-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8787)
*Effects*: Value-initializes the OuterAlloc base class and the inner allocator
object[.](#cnstr-1.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor_)
`template<class OuterA2>
scoped_allocator_adaptor(OuterA2&& outerAlloc, const InnerAllocs&... innerAllocs) noexcept;
`
[2](#cnstr-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8800)
*Constraints*: is_constructible_v<OuterAlloc, OuterA2> is true[.](#cnstr-2.sentence-1)
[3](#cnstr-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8804)
*Effects*: Initializes the OuterAlloc base class withstd::forward<OuterA2>(outerAlloc) and inner with innerAllocs... (hence recursively initializing each allocator within the adaptor with the corresponding
allocator from the argument list)[.](#cnstr-3.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor__)
`scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
`
[4](#cnstr-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8818)
*Effects*: Initializes each allocator within the adaptor with the corresponding allocator
from other[.](#cnstr-4.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor___)
`scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
`
[5](#cnstr-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8830)
*Effects*: Move constructs each allocator within the adaptor with the corresponding allocator
from other[.](#cnstr-5.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor____)
`template<class OuterA2>
scoped_allocator_adaptor(
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
`
[6](#cnstr-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8844)
*Constraints*: is_constructible_v<OuterAlloc, const OuterA2&> is true[.](#cnstr-6.sentence-1)
[7](#cnstr-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8848)
*Effects*: Initializes each allocator within the adaptor with the corresponding allocator
from other[.](#cnstr-7.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor_____)
`template<class OuterA2>
scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
`
[8](#cnstr-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8861)
*Constraints*: is_constructible_v<OuterAlloc, OuterA2> is true[.](#cnstr-8.sentence-1)
[9](#cnstr-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8865)
*Effects*: Initializes each allocator within the adaptor with the corresponding allocator rvalue
from other[.](#cnstr-9.sentence-1)
### [20.6.4](#members) Members [[allocator.adaptor.members]](allocator.adaptor.members)
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8873)
In the construct member functions,*OUTERMOST*(x) is*OUTERMOST*(x.outer_allocator()) if
the expression x.outer_allocator() is
valid ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")) andx otherwise;*OUTERMOST_ALLOC_TRAITS*(x) isallocator_traits<remove_reference_t<decltype(*OUTERMOST*(x))>>[.](#members-1.sentence-1)
[*Note [1](#members-note-1)*:
*OUTERMOST*(x) and*OUTERMOST_ALLOC_TRAITS*(x) are recursive operations[.](#members-1.sentence-2)
It
is incumbent upon the definition of outer_allocator() to ensure that the
recursion terminates[.](#members-1.sentence-3)
It will terminate for all instantiations ofscoped_allocator_adaptor[.](#members-1.sentence-4)
— *end note*]
[🔗](#lib:inner_allocator,scoped_allocator_adaptor)
`inner_allocator_type& inner_allocator() noexcept;
const inner_allocator_type& inner_allocator() const noexcept;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8897)
*Returns*: *this if sizeof...(InnerAllocs) is zero; otherwise,inner[.](#members-2.sentence-1)
[🔗](#lib:outer_allocator,scoped_allocator_adaptor)
`outer_allocator_type& outer_allocator() noexcept;
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8909)
*Returns*: static_cast<OuterAlloc&>(*this)[.](#members-3.sentence-1)
[🔗](#lib:outer_allocator,scoped_allocator_adaptor_)
`const outer_allocator_type& outer_allocator() const noexcept;
`
[4](#members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8920)
*Returns*: static_cast<const OuterAlloc&>(*this)[.](#members-4.sentence-1)
[🔗](#lib:allocate,scoped_allocator_adaptor)
`pointer allocate(size_type n);
`
[5](#members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8931)
*Returns*: allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)[.](#members-5.sentence-1)
[🔗](#lib:allocate,scoped_allocator_adaptor_)
`pointer allocate(size_type n, const_void_pointer hint);
`
[6](#members-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8942)
*Returns*: allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint)[.](#members-6.sentence-1)
[🔗](#lib:deallocate,scoped_allocator_adaptor)
`void deallocate(pointer p, size_type n) noexcept;
`
[7](#members-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8953)
*Effects*: As if by:allocator_traits<OuterAlloc>::deallocate(outer_allocator(), p, n);
[🔗](#lib:max_size,scoped_allocator_adaptor)
`size_type max_size() const;
`
[8](#members-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8965)
*Returns*: allocator_traits<OuterAlloc>::max_size(outer_allocator())[.](#members-8.sentence-1)
[🔗](#lib:construct,scoped_allocator_adaptor)
`template<class T, class... Args>
void construct(T* p, Args&&... args);
`
[9](#members-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8977)
*Effects*: Equivalent to:apply([p, this](auto&&... newargs) {*OUTERMOST_ALLOC_TRAITS*(*this)::construct(*OUTERMOST*(*this), p,
std::forward<decltype(newargs)>(newargs)...); },
uses_allocator_construction_args<T>(inner_allocator(),
std::forward<Args>(args)...));
[🔗](#lib:destroy,scoped_allocator_adaptor)
`template<class T>
void destroy(T* p);
`
[10](#members-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8998)
*Effects*: Calls *OUTERMOST_ALLOC_TRAITS*(*this)::destroy(*OUTERMOST*(*this), p)[.](#members-10.sentence-1)
[🔗](#lib:select_on_container_copy_construction,scoped_allocator_adaptor)
`scoped_allocator_adaptor select_on_container_copy_construction() const;
`
[11](#members-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L9009)
*Returns*: A new scoped_allocator_adaptor object
where each allocator a1 within the adaptor
is initialized withallocator_traits<A1>::select_on_container_copy_construction(a2),
where A1 is the type of a1 anda2 is the corresponding allocator in *this[.](#members-11.sentence-1)
### [20.6.5](#scoped.adaptor.operators) Operators [[scoped.adaptor.operators]](scoped.adaptor.operators)
[🔗](#lib:operator==,scoped_allocator_adaptor)
`template<class OuterA1, class OuterA2, class... InnerAllocs>
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
`
[1](#scoped.adaptor.operators-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L9029)
*Returns*: If sizeof...(InnerAllocs) is zero,a.outer_allocator() == b.outer_allocator() otherwisea.outer_allocator() == b.outer_allocator() && a.inner_allocator() == b.inner_allocator()

View File

@@ -0,0 +1,101 @@
[allocator.adaptor.cnstr]
# 20 Memory management library [[mem]](./#mem)
## 20.6 Class template scoped_allocator_adaptor [[allocator.adaptor]](allocator.adaptor#cnstr)
### 20.6.3 Constructors [allocator.adaptor.cnstr]
[🔗](#lib:scoped_allocator_adaptor,constructor)
`scoped_allocator_adaptor();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8787)
*Effects*: Value-initializes the OuterAlloc base class and the inner allocator
object[.](#1.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor_)
`template<class OuterA2>
scoped_allocator_adaptor(OuterA2&& outerAlloc, const InnerAllocs&... innerAllocs) noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8800)
*Constraints*: is_constructible_v<OuterAlloc, OuterA2> is true[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8804)
*Effects*: Initializes the OuterAlloc base class withstd::forward<OuterA2>(outerAlloc) and inner with innerAllocs... (hence recursively initializing each allocator within the adaptor with the corresponding
allocator from the argument list)[.](#3.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor__)
`scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8818)
*Effects*: Initializes each allocator within the adaptor with the corresponding allocator
from other[.](#4.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor___)
`scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8830)
*Effects*: Move constructs each allocator within the adaptor with the corresponding allocator
from other[.](#5.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor____)
`template<class OuterA2>
scoped_allocator_adaptor(
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8844)
*Constraints*: is_constructible_v<OuterAlloc, const OuterA2&> is true[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8848)
*Effects*: Initializes each allocator within the adaptor with the corresponding allocator
from other[.](#7.sentence-1)
[🔗](#lib:scoped_allocator_adaptor,constructor_____)
`template<class OuterA2>
scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8861)
*Constraints*: is_constructible_v<OuterAlloc, OuterA2> is true[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8865)
*Effects*: Initializes each allocator within the adaptor with the corresponding allocator rvalue
from other[.](#9.sentence-1)

View File

@@ -0,0 +1,146 @@
[allocator.adaptor.members]
# 20 Memory management library [[mem]](./#mem)
## 20.6 Class template scoped_allocator_adaptor [[allocator.adaptor]](allocator.adaptor#members)
### 20.6.4 Members [allocator.adaptor.members]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8873)
In the construct member functions,*OUTERMOST*(x) is*OUTERMOST*(x.outer_allocator()) if
the expression x.outer_allocator() is
valid ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")) andx otherwise;*OUTERMOST_ALLOC_TRAITS*(x) isallocator_traits<remove_reference_t<decltype(*OUTERMOST*(x))>>[.](#1.sentence-1)
[*Note [1](#note-1)*:
*OUTERMOST*(x) and*OUTERMOST_ALLOC_TRAITS*(x) are recursive operations[.](#1.sentence-2)
It
is incumbent upon the definition of outer_allocator() to ensure that the
recursion terminates[.](#1.sentence-3)
It will terminate for all instantiations ofscoped_allocator_adaptor[.](#1.sentence-4)
— *end note*]
[🔗](#lib:inner_allocator,scoped_allocator_adaptor)
`inner_allocator_type& inner_allocator() noexcept;
const inner_allocator_type& inner_allocator() const noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8897)
*Returns*: *this if sizeof...(InnerAllocs) is zero; otherwise,inner[.](#2.sentence-1)
[🔗](#lib:outer_allocator,scoped_allocator_adaptor)
`outer_allocator_type& outer_allocator() noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8909)
*Returns*: static_cast<OuterAlloc&>(*this)[.](#3.sentence-1)
[🔗](#lib:outer_allocator,scoped_allocator_adaptor_)
`const outer_allocator_type& outer_allocator() const noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8920)
*Returns*: static_cast<const OuterAlloc&>(*this)[.](#4.sentence-1)
[🔗](#lib:allocate,scoped_allocator_adaptor)
`pointer allocate(size_type n);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8931)
*Returns*: allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)[.](#5.sentence-1)
[🔗](#lib:allocate,scoped_allocator_adaptor_)
`pointer allocate(size_type n, const_void_pointer hint);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8942)
*Returns*: allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint)[.](#6.sentence-1)
[🔗](#lib:deallocate,scoped_allocator_adaptor)
`void deallocate(pointer p, size_type n) noexcept;
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8953)
*Effects*: As if by:allocator_traits<OuterAlloc>::deallocate(outer_allocator(), p, n);
[🔗](#lib:max_size,scoped_allocator_adaptor)
`size_type max_size() const;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8965)
*Returns*: allocator_traits<OuterAlloc>::max_size(outer_allocator())[.](#8.sentence-1)
[🔗](#lib:construct,scoped_allocator_adaptor)
`template<class T, class... Args>
void construct(T* p, Args&&... args);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8977)
*Effects*: Equivalent to:apply([p, this](auto&&... newargs) {*OUTERMOST_ALLOC_TRAITS*(*this)::construct(*OUTERMOST*(*this), p,
std::forward<decltype(newargs)>(newargs)...); },
uses_allocator_construction_args<T>(inner_allocator(),
std::forward<Args>(args)...));
[🔗](#lib:destroy,scoped_allocator_adaptor)
`template<class T>
void destroy(T* p);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8998)
*Effects*: Calls *OUTERMOST_ALLOC_TRAITS*(*this)::destroy(*OUTERMOST*(*this), p)[.](#10.sentence-1)
[🔗](#lib:select_on_container_copy_construction,scoped_allocator_adaptor)
`scoped_allocator_adaptor select_on_container_copy_construction() const;
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L9009)
*Returns*: A new scoped_allocator_adaptor object
where each allocator a1 within the adaptor
is initialized withallocator_traits<A1>::select_on_container_copy_construction(a2),
where A1 is the type of a1 anda2 is the corresponding allocator in *this[.](#11.sentence-1)

View File

@@ -0,0 +1,68 @@
[allocator.adaptor.syn]
# 20 Memory management library [[mem]](./#mem)
## 20.6 Class template scoped_allocator_adaptor [[allocator.adaptor]](allocator.adaptor#syn)
### 20.6.1 Header <scoped_allocator> synopsis [allocator.adaptor.syn]
[🔗](#header:%3cscoped_allocator%3e)
namespace std {// class template scoped_allocator_adaptortemplate<class OuterAlloc, class... InnerAlloc>class scoped_allocator_adaptor; // [[scoped.adaptor.operators]](scoped.adaptor.operators "20.6.5Operators"), scoped allocator operatorstemplate<class OuterA1, class OuterA2, class... InnerAllocs>bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8608)
The class template scoped_allocator_adaptor is an allocator template that
specifies an allocator resource (the outer allocator) to be used by a container (as any
other allocator does) and also specifies an inner allocator resource to be passed to the
constructor of every element within the container[.](#1.sentence-1)
This adaptor is instantiated with one
outer and zero or more inner allocator types[.](#1.sentence-2)
If instantiated with only one allocator
type, the inner allocator becomes the scoped_allocator_adaptor itself, thus
using the same allocator resource for the container and every element within the
container and, if the elements themselves are containers, each of their elements
recursively[.](#1.sentence-3)
If instantiated with more than one allocator, the first allocator is the
outer allocator for use by the container, the second allocator is passed to the
constructors of the container's elements, and, if the elements themselves are
containers, the third allocator is passed to the elements' elements, and so on[.](#1.sentence-4)
If
containers are nested to a depth greater than the number of allocators, the last
allocator is used repeatedly, as in the single-allocator case, for any remaining
recursions[.](#1.sentence-5)
[*Note [1](#note-1)*:
The scoped_allocator_adaptor is derived from the outer
allocator type so it can be substituted for the outer allocator type in most
expressions[.](#1.sentence-6)
— *end note*]
[🔗](#lib:scoped_allocator_adaptor)
namespace std {template<class OuterAlloc, class... InnerAllocs>class scoped_allocator_adaptor : public OuterAlloc {private:using OuterTraits = allocator_traits<OuterAlloc>; // *exposition only* scoped_allocator_adaptor<InnerAllocs...> inner; // *exposition only*public:using outer_allocator_type = OuterAlloc; using inner_allocator_type = *see below*; using value_type = typename OuterTraits::value_type; using size_type = typename OuterTraits::size_type; using difference_type = typename OuterTraits::difference_type; using pointer = typename OuterTraits::pointer; using const_pointer = typename OuterTraits::const_pointer; using void_pointer = typename OuterTraits::void_pointer; using const_void_pointer = typename OuterTraits::const_void_pointer; using propagate_on_container_copy_assignment = *see below*; using propagate_on_container_move_assignment = *see below*; using propagate_on_container_swap = *see below*; using is_always_equal = *see below*; template<class Tp> struct rebind {using other = scoped_allocator_adaptor< OuterTraits::template rebind_alloc<Tp>, InnerAllocs...>; };
scoped_allocator_adaptor(); template<class OuterA2> scoped_allocator_adaptor(OuterA2&& outerAlloc, const InnerAllocs&... innerAllocs) noexcept;
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept; template<class OuterA2> scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept; template<class OuterA2> scoped_allocator_adaptor( scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; ~scoped_allocator_adaptor();
inner_allocator_type& inner_allocator() noexcept; const inner_allocator_type& inner_allocator() const noexcept;
outer_allocator_type& outer_allocator() noexcept; const outer_allocator_type& outer_allocator() const noexcept;
pointer allocate(size_type n);
pointer allocate(size_type n, const_void_pointer hint); void deallocate(pointer p, size_type n);
size_type max_size() const; template<class T, class... Args>void construct(T* p, Args&&... args); template<class T>void destroy(T* p);
scoped_allocator_adaptor select_on_container_copy_construction() const; }; template<class OuterAlloc, class... InnerAllocs> scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)-> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;}

View File

@@ -0,0 +1,65 @@
[allocator.adaptor.types]
# 20 Memory management library [[mem]](./#mem)
## 20.6 Class template scoped_allocator_adaptor [[allocator.adaptor]](allocator.adaptor#types)
### 20.6.2 Member types [allocator.adaptor.types]
[🔗](#lib:inner_allocator_type,scoped_allocator_adaptor)
`using inner_allocator_type = see below;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8722)
*Type*: scoped_allocator_adaptor<OuterAlloc> if sizeof...(InnerAllocs) is
zero; otherwise,
scoped_allocator_adaptor<InnerAllocs...>[.](#1.sentence-2)
[🔗](#lib:propagate_on_container_copy_assignment,scoped_allocator_adaptor)
`using propagate_on_container_copy_assignment = see below;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8733)
*Type*: true_type ifallocator_traits<A>::propagate_on_container_copy_assignment::value istrue for any A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#2.sentence-1)
[🔗](#lib:propagate_on_container_move_assignment,scoped_allocator_adaptor)
`using propagate_on_container_move_assignment = see below;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8746)
*Type*: true_type ifallocator_traits<A>::propagate_on_container_move_assignment::value istrue for any A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#3.sentence-1)
[🔗](#lib:propagate_on_container_swap,scoped_allocator_adaptor)
`using propagate_on_container_swap = see below;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8759)
*Type*: true_type ifallocator_traits<A>::propagate_on_container_swap::value istrue for any A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#4.sentence-1)
[🔗](#lib:is_always_equal,scoped_allocator_adaptor)
`using is_always_equal = see below;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8772)
*Type*: true_type ifallocator_traits<A>::is_always_equal::value istrue for every A in the set of OuterAlloc andInnerAllocs...; otherwise, false_type[.](#5.sentence-1)

View File

@@ -0,0 +1,21 @@
[allocator.globals]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.globals)
### 20.2.10 The default allocator [[default.allocator]](default.allocator#allocator.globals)
#### 20.2.10.3 Operators [allocator.globals]
[🔗](#lib:operator==,allocator)
`template<class T, class U>
constexpr bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2104)
*Returns*: true[.](#1.sentence-1)

View File

@@ -0,0 +1,129 @@
[allocator.members]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.members)
### 20.2.10 The default allocator [[default.allocator]](default.allocator#allocator.members)
#### 20.2.10.2 Members [allocator.members]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1994)
Except for the destructor, member functions of the default allocator shall not introduce
data races ([[intro.multithread]](intro.multithread "6.10.2Multi-threaded executions and data races")) as a result of concurrent calls to those member
functions from different threads[.](#1.sentence-1)
Calls to these functions that allocate or deallocate a
particular unit of storage shall occur in a single total order, and each such
deallocation call shall happen before the next allocation (if any) in this order[.](#1.sentence-2)
[🔗](#lib:allocate,allocator)
`constexpr T* allocate(size_t n);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2007)
*Mandates*: T is not an incomplete type ([[basic.types.general]](basic.types.general#term.incomplete.type "6.9.1General"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2011)
*Returns*: A pointer to the initial element of an array of n T[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2015)
*Throws*: bad_array_new_length ifnumeric_limits<size_t>::max() / sizeof(T) < n, orbad_alloc if the storage cannot be obtained[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2021)
*Remarks*: The storage for the array
is obtained by calling ::operator new ([[new.delete]](new.delete "17.6.3Storage allocation and deallocation")),
but it is unspecified when or how often this
function is called[.](#5.sentence-1)
This function starts the lifetime of the array object,
but not that of any of the array elements[.](#5.sentence-2)
[🔗](#lib:allocate_at_least,allocator)
`constexpr allocation_result<T*> allocate_at_least(size_t n);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2037)
*Mandates*: T is not an incomplete type ([[basic.types.general]](basic.types.general#term.incomplete.type "6.9.1General"))[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2041)
*Returns*: allocation_result<T*>{ptr, count},
where ptr is a pointer to
the initial element of an array of count T andcount ≥ n[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2048)
*Throws*: bad_array_new_length if numeric_limits<size_t>::max() / sizeof(T) < n,
or bad_alloc if the storage cannot be obtained[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2054)
*Remarks*: The storage for the array is obtained by calling ::operator new,
but it is unspecified when or how often this function is called[.](#9.sentence-1)
This function starts the lifetime of the array object,
but not that of any of the array elements[.](#9.sentence-2)
[🔗](#lib:deallocate,allocator)
`constexpr void deallocate(T* p, size_t n);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2068)
*Preconditions*:
- [(10.1)](#10.1)
If p is memory that was obtained by a call to allocate_at_least,
let ret be the value returned andreq be the value passed as the first argument to that call[.](#10.1.sentence-1)
p is equal to ret.ptr andn is a value such that req ≤ n ≤ ret.count[.](#10.1.sentence-2)
- [(10.2)](#10.2)
Otherwise, p is a pointer value obtained from allocate[.](#10.2.sentence-1)
n equals the value passed as the first argument
to the invocation of allocate which returned p[.](#10.2.sentence-2)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2083)
*Effects*: Deallocates the storage referenced by p[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2087)
*Remarks*: Uses::operator delete ([[new.delete]](new.delete "17.6.3Storage allocation and deallocation")),
but it is unspecified
when this function is called[.](#12.sentence-1)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
[allocator.requirements.completeness]
# 16 Library introduction [[library]](./#library)
## 16.4 Library-wide requirements [[requirements]](requirements#allocator.requirements.completeness)
### 16.4.4 Requirements on types and expressions [[utility.requirements]](utility.requirements#allocator.requirements.completeness)
#### 16.4.4.6 *Cpp17Allocator* requirements [[allocator.requirements]](allocator.requirements#completeness)
#### 16.4.4.6.2 Allocator completeness requirements [allocator.requirements.completeness]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2964)
If X is an allocator class for type T,X additionally meets the allocator completeness requirements if,
whether or not T is a complete type:
- [(1.1)](#1.1)
X is a complete type, and
- [(1.2)](#1.2)
all the member types of [allocator_traits<X>](allocator.traits "20.2.9Allocator traits[allocator.traits]") other than value_type are complete types[.](#1.sentence-1)

File diff suppressed because it is too large Load Diff

25
cppdraft/allocator/tag.md Normal file
View File

@@ -0,0 +1,25 @@
[allocator.tag]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.tag)
### 20.2.7 Allocator argument tag [allocator.tag]
[🔗](#lib:allocator_arg_t)
`namespace std {
struct allocator_arg_t { explicit allocator_arg_t() = default; };
inline constexpr allocator_arg_t allocator_arg{};
}
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1271)
The allocator_arg_t struct is an empty class type used as a unique type to
disambiguate constructor and function overloading[.](#1.sentence-1)
Specifically, several types (seetuple [[tuple]](tuple "22.4Tuples")) have constructors with allocator_arg_t as the first
argument, immediately followed by an argument of a type that meets the[*Cpp17Allocator*](allocator.requirements.general#:Cpp17Allocator "16.4.4.6.1General[allocator.requirements.general]") requirements ([[allocator.requirements.general]](allocator.requirements.general "16.4.4.6.1General"))[.](#1.sentence-2)

View File

@@ -0,0 +1,292 @@
[allocator.traits]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.traits)
### 20.2.9 Allocator traits [allocator.traits]
#### [20.2.9.1](#general) General [[allocator.traits.general]](allocator.traits.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1640)
The class template allocator_traits supplies a uniform interface to all
allocator types[.](#general-1.sentence-1)
An allocator cannot be a non-class type, however, even if allocator_traits supplies the entire required interface[.](#general-1.sentence-2)
[*Note [1](#general-note-1)*:
Thus, it is always possible to create
a derived class from an allocator[.](#general-1.sentence-3)
— *end note*]
If a program declares
an explicit or partial specialization of allocator_traits,
the program is ill-formed, no diagnostic required[.](#general-1.sentence-4)
[🔗](#lib:allocator_traits)
namespace std {template<class Alloc> struct allocator_traits {using allocator_type = Alloc; using value_type = typename Alloc::value_type; using pointer = *see below*; using const_pointer = *see below*; using void_pointer = *see below*; using const_void_pointer = *see below*; using difference_type = *see below*; using size_type = *see below*; using propagate_on_container_copy_assignment = *see below*; using propagate_on_container_move_assignment = *see below*; using propagate_on_container_swap = *see below*; using is_always_equal = *see below*; template<class T> using rebind_alloc = *see below*; template<class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; static constexpr pointer allocate(Alloc& a, size_type n); static constexpr pointer allocate(Alloc& a, size_type n, const_void_pointer hint); static constexpr allocation_result<pointer, size_type> allocate_at_least(Alloc& a, size_type n); static constexpr void deallocate(Alloc& a, pointer p, size_type n); template<class T, class... Args>static constexpr void construct(Alloc& a, T* p, Args&&... args); template<class T>static constexpr void destroy(Alloc& a, T* p); static constexpr size_type max_size(const Alloc& a) noexcept; static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs); };}
#### [20.2.9.2](#types) Member types [[allocator.traits.types]](allocator.traits.types)
[🔗](#lib:pointer,allocator_traits)
`using pointer = see below;
`
[1](#types-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1705)
*Type*: Alloc::pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise, value_type*[.](#types-1.sentence-1)
[🔗](#lib:const_pointer,allocator_traits)
`using const_pointer = see below;
`
[2](#types-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1717)
*Type*: Alloc::const_pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::const_pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::rebind<const value_type>[.](#types-2.sentence-1)
[🔗](#lib:void_pointer,allocator_traits)
`using void_pointer = see below;
`
[3](#types-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1730)
*Type*: Alloc::void_pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::void_pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::rebind<void>[.](#types-3.sentence-1)
[🔗](#lib:const_void_pointer,allocator_traits)
`using const_void_pointer = see below;
`
[4](#types-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1743)
*Type*: Alloc::const_void_pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::const_void_pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::rebind<const void>[.](#types-4.sentence-1)
[🔗](#lib:difference_type,allocator_traits)
`using difference_type = see below;
`
[5](#types-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1756)
*Type*: Alloc::difference_type if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::difference_type is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::difference_type[.](#types-5.sentence-1)
[🔗](#lib:size_type,allocator_traits)
`using size_type = see below;
`
[6](#types-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1769)
*Type*: Alloc::size_type if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::size_type is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,make_unsigned_t<difference_type>[.](#types-6.sentence-1)
[🔗](#lib:propagate_on_container_copy_assignment,allocator_traits)
`using propagate_on_container_copy_assignment = see below;
`
[7](#types-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1782)
*Type*: Alloc::propagate_on_container_copy_assignment if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::propagate_on_container_copy_assignment is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwisefalse_type[.](#types-7.sentence-1)
[🔗](#lib:propagate_on_container_move_assignment,allocator_traits)
`using propagate_on_container_move_assignment = see below;
`
[8](#types-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1795)
*Type*: Alloc::propagate_on_container_move_assignment if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::propagate_on_container_move_assignment is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwisefalse_type[.](#types-8.sentence-1)
[🔗](#lib:propagate_on_container_swap,allocator_traits)
`using propagate_on_container_swap = see below;
`
[9](#types-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1808)
*Type*: Alloc::propagate_on_container_swap if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::propagate_on_container_swap is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwisefalse_type[.](#types-9.sentence-1)
[🔗](#lib:is_always_equal,allocator_traits)
`using is_always_equal = see below;
`
[10](#types-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1821)
*Type*: Alloc::is_always_equal if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::is_always_equal is valid and denotes a type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction"));
otherwise is_empty<Alloc>::type[.](#types-10.sentence-1)
[🔗](#lib:rebind_alloc,allocator_traits)
`template<class T> using rebind_alloc = see below;
`
[11](#types-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1834)
*Alias template*: Alloc::rebind<T>::other if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::rebind<T>::other is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,Alloc<T, Args> if Alloc is a class template instantiation
of the form Alloc<U, Args>, where Args is zero or more type arguments;
otherwise, the instantiation of rebind_alloc is ill-formed[.](#types-11.sentence-1)
#### [20.2.9.3](#members) Static member functions [[allocator.traits.members]](allocator.traits.members)
[🔗](#lib:allocate,allocator_traits)
`static constexpr pointer allocate(Alloc& a, size_type n);
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1851)
*Returns*: a.allocate(n)[.](#members-1.sentence-1)
[🔗](#lib:allocate,allocator_traits_)
`static constexpr pointer allocate(Alloc& a, size_type n, const_void_pointer hint);
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1862)
*Returns*: a.allocate(n, hint) if that expression is well-formed; otherwise, a.allocate(n)[.](#members-2.sentence-1)
[🔗](#lib:allocate_at_least,allocator_traits)
`static constexpr allocation_result<pointer, size_type> allocate_at_least(Alloc& a, size_type n);
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1873)
*Returns*: a.allocate_at_least(n) if that expression is well-formed;
otherwise, {a.allocate(n), n}[.](#members-3.sentence-1)
[🔗](#lib:deallocate,allocator_traits)
`static constexpr void deallocate(Alloc& a, pointer p, size_type n);
`
[4](#members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1885)
*Effects*: Calls a.deallocate(p, n)[.](#members-4.sentence-1)
[5](#members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1889)
*Throws*: Nothing[.](#members-5.sentence-1)
[🔗](#lib:construct,allocator_traits)
`template<class T, class... Args>
static constexpr void construct(Alloc& a, T* p, Args&&... args);
`
[6](#members-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1901)
*Effects*: Calls a.construct(p, std::forward<Args>(args)...) if that call is well-formed;
otherwise, invokes construct_at(p, std::forward<Args>(args)...)[.](#members-6.sentence-1)
[🔗](#lib:destroy,allocator_traits)
`template<class T>
static constexpr void destroy(Alloc& a, T* p);
`
[7](#members-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1915)
*Effects*: Calls a.destroy(p) if that call is well-formed; otherwise, invokesdestroy_at(p)[.](#members-7.sentence-1)
[🔗](#lib:max_size,allocator_traits)
`static constexpr size_type max_size(const Alloc& a) noexcept;
`
[8](#members-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1927)
*Returns*: a.max_size() if that expression is well-formed; otherwise,numeric_limits<size_type>::max() / sizeof(value_type)[.](#members-8.sentence-1)
[🔗](#lib:select_on_container_copy_construction,allocator_traits)
`static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs);
`
[9](#members-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1939)
*Returns*: rhs.select_on_container_copy_construction() if that expression is
well-formed; otherwise, rhs[.](#members-9.sentence-1)
#### [20.2.9.4](#other) Other [[allocator.traits.other]](allocator.traits.other)
[1](#other-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1947)
The class template allocation_result has
the template parameters, data members, and special members specified above[.](#other-1.sentence-1)
It has no base classes or members other than those specified[.](#other-1.sentence-2)

View File

@@ -0,0 +1,33 @@
[allocator.traits.general]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.traits.general)
### 20.2.9 Allocator traits [[allocator.traits]](allocator.traits#general)
#### 20.2.9.1 General [allocator.traits.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1640)
The class template allocator_traits supplies a uniform interface to all
allocator types[.](#1.sentence-1)
An allocator cannot be a non-class type, however, even if allocator_traits supplies the entire required interface[.](#1.sentence-2)
[*Note [1](#note-1)*:
Thus, it is always possible to create
a derived class from an allocator[.](#1.sentence-3)
— *end note*]
If a program declares
an explicit or partial specialization of allocator_traits,
the program is ill-formed, no diagnostic required[.](#1.sentence-4)
[🔗](#lib:allocator_traits)
namespace std {template<class Alloc> struct allocator_traits {using allocator_type = Alloc; using value_type = typename Alloc::value_type; using pointer = *see below*; using const_pointer = *see below*; using void_pointer = *see below*; using const_void_pointer = *see below*; using difference_type = *see below*; using size_type = *see below*; using propagate_on_container_copy_assignment = *see below*; using propagate_on_container_move_assignment = *see below*; using propagate_on_container_swap = *see below*; using is_always_equal = *see below*; template<class T> using rebind_alloc = *see below*; template<class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; static constexpr pointer allocate(Alloc& a, size_type n); static constexpr pointer allocate(Alloc& a, size_type n, const_void_pointer hint); static constexpr allocation_result<pointer, size_type> allocate_at_least(Alloc& a, size_type n); static constexpr void deallocate(Alloc& a, pointer p, size_type n); template<class T, class... Args>static constexpr void construct(Alloc& a, T* p, Args&&... args); template<class T>static constexpr void destroy(Alloc& a, T* p); static constexpr size_type max_size(const Alloc& a) noexcept; static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs); };}

View File

@@ -0,0 +1,108 @@
[allocator.traits.members]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.traits.members)
### 20.2.9 Allocator traits [[allocator.traits]](allocator.traits#members)
#### 20.2.9.3 Static member functions [allocator.traits.members]
[🔗](#lib:allocate,allocator_traits)
`static constexpr pointer allocate(Alloc& a, size_type n);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1851)
*Returns*: a.allocate(n)[.](#1.sentence-1)
[🔗](#lib:allocate,allocator_traits_)
`static constexpr pointer allocate(Alloc& a, size_type n, const_void_pointer hint);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1862)
*Returns*: a.allocate(n, hint) if that expression is well-formed; otherwise, a.allocate(n)[.](#2.sentence-1)
[🔗](#lib:allocate_at_least,allocator_traits)
`static constexpr allocation_result<pointer, size_type> allocate_at_least(Alloc& a, size_type n);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1873)
*Returns*: a.allocate_at_least(n) if that expression is well-formed;
otherwise, {a.allocate(n), n}[.](#3.sentence-1)
[🔗](#lib:deallocate,allocator_traits)
`static constexpr void deallocate(Alloc& a, pointer p, size_type n);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1885)
*Effects*: Calls a.deallocate(p, n)[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1889)
*Throws*: Nothing[.](#5.sentence-1)
[🔗](#lib:construct,allocator_traits)
`template<class T, class... Args>
static constexpr void construct(Alloc& a, T* p, Args&&... args);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1901)
*Effects*: Calls a.construct(p, std::forward<Args>(args)...) if that call is well-formed;
otherwise, invokes construct_at(p, std::forward<Args>(args)...)[.](#6.sentence-1)
[🔗](#lib:destroy,allocator_traits)
`template<class T>
static constexpr void destroy(Alloc& a, T* p);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1915)
*Effects*: Calls a.destroy(p) if that call is well-formed; otherwise, invokesdestroy_at(p)[.](#7.sentence-1)
[🔗](#lib:max_size,allocator_traits)
`static constexpr size_type max_size(const Alloc& a) noexcept;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1927)
*Returns*: a.max_size() if that expression is well-formed; otherwise,numeric_limits<size_type>::max() / sizeof(value_type)[.](#8.sentence-1)
[🔗](#lib:select_on_container_copy_construction,allocator_traits)
`static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1939)
*Returns*: rhs.select_on_container_copy_construction() if that expression is
well-formed; otherwise, rhs[.](#9.sentence-1)

View File

@@ -0,0 +1,18 @@
[allocator.traits.other]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.traits.other)
### 20.2.9 Allocator traits [[allocator.traits]](allocator.traits#other)
#### 20.2.9.4 Other [allocator.traits.other]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1947)
The class template allocation_result has
the template parameters, data members, and special members specified above[.](#1.sentence-1)
It has no base classes or members other than those specified[.](#1.sentence-2)

View File

@@ -0,0 +1,154 @@
[allocator.traits.types]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.traits.types)
### 20.2.9 Allocator traits [[allocator.traits]](allocator.traits#types)
#### 20.2.9.2 Member types [allocator.traits.types]
[🔗](#lib:pointer,allocator_traits)
`using pointer = see below;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1705)
*Type*: Alloc::pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise, value_type*[.](#1.sentence-1)
[🔗](#lib:const_pointer,allocator_traits)
`using const_pointer = see below;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1717)
*Type*: Alloc::const_pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::const_pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::rebind<const value_type>[.](#2.sentence-1)
[🔗](#lib:void_pointer,allocator_traits)
`using void_pointer = see below;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1730)
*Type*: Alloc::void_pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::void_pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::rebind<void>[.](#3.sentence-1)
[🔗](#lib:const_void_pointer,allocator_traits)
`using const_void_pointer = see below;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1743)
*Type*: Alloc::const_void_pointer if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::const_void_pointer is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::rebind<const void>[.](#4.sentence-1)
[🔗](#lib:difference_type,allocator_traits)
`using difference_type = see below;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1756)
*Type*: Alloc::difference_type if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::difference_type is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,pointer_traits<pointer>::difference_type[.](#5.sentence-1)
[🔗](#lib:size_type,allocator_traits)
`using size_type = see below;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1769)
*Type*: Alloc::size_type if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::size_type is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,make_unsigned_t<difference_type>[.](#6.sentence-1)
[🔗](#lib:propagate_on_container_copy_assignment,allocator_traits)
`using propagate_on_container_copy_assignment = see below;
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1782)
*Type*: Alloc::propagate_on_container_copy_assignment if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::propagate_on_container_copy_assignment is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwisefalse_type[.](#7.sentence-1)
[🔗](#lib:propagate_on_container_move_assignment,allocator_traits)
`using propagate_on_container_move_assignment = see below;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1795)
*Type*: Alloc::propagate_on_container_move_assignment if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::propagate_on_container_move_assignment is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwisefalse_type[.](#8.sentence-1)
[🔗](#lib:propagate_on_container_swap,allocator_traits)
`using propagate_on_container_swap = see below;
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1808)
*Type*: Alloc::propagate_on_container_swap if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::propagate_on_container_swap is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwisefalse_type[.](#9.sentence-1)
[🔗](#lib:is_always_equal,allocator_traits)
`using is_always_equal = see below;
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1821)
*Type*: Alloc::is_always_equal if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::is_always_equal is valid and denotes a type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction"));
otherwise is_empty<Alloc>::type[.](#10.sentence-1)
[🔗](#lib:rebind_alloc,allocator_traits)
`template<class T> using rebind_alloc = see below;
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1834)
*Alias template*: Alloc::rebind<T>::other if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Alloc::rebind<T>::other is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,Alloc<T, Args> if Alloc is a class template instantiation
of the form Alloc<U, Args>, where Args is zero or more type arguments;
otherwise, the instantiation of rebind_alloc is ill-formed[.](#11.sentence-1)

343
cppdraft/allocator/uses.md Normal file
View File

@@ -0,0 +1,343 @@
[allocator.uses]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.uses)
### 20.2.8 uses_allocator [allocator.uses]
#### [20.2.8.1](#trait) uses_allocator trait [[allocator.uses.trait]](allocator.uses.trait)
[🔗](#lib:uses_allocator)
`template<class T, class Alloc> struct uses_allocator;
`
[1](#trait-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1288)
*Remarks*: Automatically detects whether T has a nested allocator_type that
is convertible from Alloc[.](#trait-1.sentence-1)
Meets the [*Cpp17BinaryTypeTrait*](meta.rqmts#:Cpp17BinaryTypeTrait "21.3.2Requirements[meta.rqmts]") requirements ([[meta.rqmts]](meta.rqmts "21.3.2Requirements"))[.](#trait-1.sentence-2)
The implementation shall provide a definition that is
derived from true_type if the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") T::allocator_type is valid and denotes a type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")) andis_convertible_v<Alloc, T::allocator_type> != false, otherwise it shall be
derived from false_type[.](#trait-1.sentence-3)
A program may specialize this template to derive fromtrue_type for a program-defined type T that does not have a nestedallocator_type but nonetheless can be constructed with an allocator where
either:
- [(1.1)](#trait-1.1)
the first argument of a constructor has type allocator_arg_t and the
second argument has type Alloc or
- [(1.2)](#trait-1.2)
the last argument of a constructor has type Alloc[.](#trait-1.sentence-4)
#### [20.2.8.2](#construction) Uses-allocator construction [[allocator.uses.construction]](allocator.uses.construction)
[1](#construction-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1310)
[*Uses-allocator construction*](#def:uses-allocator_construction "20.2.8.2Uses-allocator construction[allocator.uses.construction]") with allocator alloc and constructor arguments args... refers to the construction of an object of type T such that alloc is passed to the constructor of T if T uses an allocator type compatible with alloc[.](#construction-1.sentence-1)
When applied to the construction of an object of type T,
it is equivalent to initializing it with the value of the expressionmake_obj_using_allocator<T>(alloc, args...), described below[.](#construction-1.sentence-2)
[2](#construction-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1320)
The following utility functions support
three conventions for passing alloc to a constructor:
- [(2.1)](#construction-2.1)
If T does not use an allocator compatible with alloc,
then alloc is ignored[.](#construction-2.1.sentence-1)
- [(2.2)](#construction-2.2)
Otherwise, if T has a constructor invocable as T(allocator_arg, alloc, args...) (leading-allocator convention),
then uses-allocator construction chooses this constructor form[.](#construction-2.2.sentence-1)
- [(2.3)](#construction-2.3)
Otherwise, if T has a constructor invocable as T(args..., alloc) (trailing-allocator convention),
then uses-allocator construction chooses this constructor form[.](#construction-2.3.sentence-1)
[3](#construction-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1337)
The uses_allocator_construction_args function template
takes an allocator and argument list and
produces (as a tuple) a new argument list matching one of the above conventions[.](#construction-3.sentence-1)
Additionally, overloads are provided
that treat specializations of pair such that uses-allocator construction is applied individually
to the first and second data members[.](#construction-3.sentence-2)
The make_obj_using_allocator anduninitialized_construct_using_allocator function templates
apply the modified constructor arguments
to construct an object of type T as a return value or in-place, respectively[.](#construction-3.sentence-3)
[*Note [1](#construction-note-1)*:
For uses_allocator_construction_args andmake_obj_using_allocator, type T is not deduced and must therefore be specified explicitly by the caller[.](#construction-3.sentence-4)
— *end note*]
[🔗](#lib:uses_allocator_construction_args)
`template<class T, class Alloc, class... Args>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
Args&&... args) noexcept;
`
[4](#construction-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1364)
*Constraints*: remove_cv_t<T> is not a specialization of pair[.](#construction-4.sentence-1)
[5](#construction-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1368)
*Returns*: A tuple value determined as follows:
- [(5.1)](#construction-5.1)
If uses_allocator_v<remove_cv_t<T>, Alloc> is false and is_constructible_v<T, Args...> is true,
return forward_as_tuple(std::forward<Args>(args)...)[.](#construction-5.1.sentence-1)
- [(5.2)](#construction-5.2)
Otherwise, if uses_allocator_v<remove_cv_t<T>, Alloc> is true and is_constructible_v<T, allocator_arg_t, const Alloc&, Args...> is true,
returntuple<allocator_arg_t, const Alloc&, Args&&...>( allocator_arg, alloc, std::forward<Args>(args)...)
- [(5.3)](#construction-5.3)
Otherwise, if uses_allocator_v<remove_cv_t<T>, Alloc> is true and is_constructible_v<T, Args..., const Alloc&> is true,
return forward_as_tuple(std::forward<Args>(args)..., alloc)[.](#construction-5.3.sentence-1)
- [(5.4)](#construction-5.4)
Otherwise, the program is ill-formed[.](#construction-5.4.sentence-1)
[*Note [2](#construction-note-2)*:
This definition prevents a silent failure
to pass the allocator to a constructor of a type for whichuses_allocator_v<T, Alloc> is true[.](#construction-5.sentence-2)
— *end note*]
[🔗](#lib:uses_allocator_construction_args_)
`template<class T, class Alloc, class Tuple1, class Tuple2>
constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
Tuple1&& x, Tuple2&& y) noexcept;
`
[6](#construction-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1407)
Let T1 be T::first_type[.](#construction-6.sentence-1)
Let T2 be T::second_type[.](#construction-6.sentence-2)
[7](#construction-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1411)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#construction-7.sentence-1)
[8](#construction-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1415)
*Effects*: Equivalent to:return make_tuple( piecewise_construct,
apply([&alloc](auto&&... args1) {return uses_allocator_construction_args<T1>( alloc, std::forward<decltype(args1)>(args1)...); }, std::forward<Tuple1>(x)),
apply([&alloc](auto&&... args2) {return uses_allocator_construction_args<T2>( alloc, std::forward<decltype(args2)>(args2)...); }, std::forward<Tuple2>(y)));
[🔗](#lib:uses_allocator_construction_args__)
`template<class T, class Alloc>
constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
`
[9](#construction-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1439)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#construction-9.sentence-1)
[10](#construction-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1443)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
tuple<>{}, tuple<>{});
[🔗](#lib:uses_allocator_construction_args___)
`template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
U&& u, V&& v) noexcept;
`
[11](#construction-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1460)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#construction-11.sentence-1)
[12](#construction-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1464)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(std::forward<U>(u)),
forward_as_tuple(std::forward<V>(v)));
[🔗](#lib:uses_allocator_construction_args____)
`template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
pair<U, V>& pr) noexcept;
template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
const pair<U, V>& pr) noexcept;
`
[13](#construction-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1485)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#construction-13.sentence-1)
[14](#construction-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1489)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(pr.first),
forward_as_tuple(pr.second));
[🔗](#lib:uses_allocator_construction_args_____)
`template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
pair<U, V>&& pr) noexcept;
template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
const pair<U, V>&& pr) noexcept;
`
[15](#construction-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1510)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#construction-15.sentence-1)
[16](#construction-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1514)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(get<0>(std::move(pr))),
forward_as_tuple(get<1>(std::move(pr))));
[🔗](#lib:uses_allocator_construction_args______)
`template<class T, class Alloc, [pair-like](tuple.syn#concept:pair-like "22.4.2Header <tuple> synopsis[tuple.syn]") P>
constexpr auto uses_allocator_construction_args(const Alloc& alloc, P&& p) noexcept;
`
[17](#construction-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1531)
*Constraints*: remove_cv_t<T> is a specialization of pair andremove_cvref_t<P> is not a specialization of ranges::subrange[.](#construction-17.sentence-1)
[18](#construction-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1536)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(get<0>(std::forward<P>(p))),
forward_as_tuple(get<1>(std::forward<P>(p))));
[🔗](#lib:uses_allocator_construction_args_______)
`template<class T, class Alloc, class U>
constexpr auto uses_allocator_construction_args(const Alloc& alloc, U&& u) noexcept;
`
[19](#construction-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1553)
Let *FUN* be the function template:template<class A, class B>void *FUN*(const pair<A, B>&);
[20](#construction-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1560)
*Constraints*: remove_cv_t<T> is a specialization of pair, and either:
- [(20.1)](#construction-20.1)
remove_cvref_t<U> is a specialization of ranges::subrange, or
- [(20.2)](#construction-20.2)
U does not satisfy [*pair-like*](tuple.syn#concept:pair-like "22.4.2Header <tuple> synopsis[tuple.syn]") and
the expression *FUN*(u) is not well-formed
when considered as an unevaluated operand[.](#construction-20.sentence-1)
[21](#construction-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1572)
Let *pair-constructor* be an exposition-only class defined as follows:class *pair-constructor* {using *pair-type* = remove_cv_t<T>; // *exposition only*constexpr auto *do-construct*(const *pair-type*& p) const { // *exposition only*return make_obj_using_allocator<*pair-type*>(*alloc_*, p); }constexpr auto *do-construct*(*pair-type*&& p) const { // *exposition only*return make_obj_using_allocator<*pair-type*>(*alloc_*, std::move(p)); }const Alloc& *alloc_*; // *exposition only* U& *u_*; // *exposition only*public:constexpr operator *pair-type*() const {return *do-construct*(std::forward<U>(*u_*)); }};
[22](#construction-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1595)
*Returns*: make_tuple(pc),
where pc is a *pair-constructor* object
whose *alloc_* member is initialized with alloc and
whose *u_* member is initialized with u[.](#construction-22.sentence-1)
[🔗](#lib:make_obj_using_allocator)
`template<class T, class Alloc, class... Args>
constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args);
`
[23](#construction-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1610)
*Effects*: Equivalent to:return make_from_tuple<T>(uses_allocator_construction_args<T>( alloc, std::forward<Args>(args)...));
[🔗](#lib:uninitialized_construct_using_allocator)
`template<class T, class Alloc, class... Args>
constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args);
`
[24](#construction-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1626)
*Effects*: Equivalent to:return apply([&]<class... U>(U&&... xs) {return construct_at(p, std::forward<U>(xs)...); }, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));

View File

@@ -0,0 +1,311 @@
[allocator.uses.construction]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#allocator.uses.construction)
### 20.2.8 uses_allocator [[allocator.uses]](allocator.uses#construction)
#### 20.2.8.2 Uses-allocator construction [allocator.uses.construction]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1310)
[*Uses-allocator construction*](#def:uses-allocator_construction "20.2.8.2Uses-allocator construction[allocator.uses.construction]") with allocator alloc and constructor arguments args... refers to the construction of an object of type T such that alloc is passed to the constructor of T if T uses an allocator type compatible with alloc[.](#1.sentence-1)
When applied to the construction of an object of type T,
it is equivalent to initializing it with the value of the expressionmake_obj_using_allocator<T>(alloc, args...), described below[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1320)
The following utility functions support
three conventions for passing alloc to a constructor:
- [(2.1)](#2.1)
If T does not use an allocator compatible with alloc,
then alloc is ignored[.](#2.1.sentence-1)
- [(2.2)](#2.2)
Otherwise, if T has a constructor invocable as T(allocator_arg, alloc, args...) (leading-allocator convention),
then uses-allocator construction chooses this constructor form[.](#2.2.sentence-1)
- [(2.3)](#2.3)
Otherwise, if T has a constructor invocable as T(args..., alloc) (trailing-allocator convention),
then uses-allocator construction chooses this constructor form[.](#2.3.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1337)
The uses_allocator_construction_args function template
takes an allocator and argument list and
produces (as a tuple) a new argument list matching one of the above conventions[.](#3.sentence-1)
Additionally, overloads are provided
that treat specializations of pair such that uses-allocator construction is applied individually
to the first and second data members[.](#3.sentence-2)
The make_obj_using_allocator anduninitialized_construct_using_allocator function templates
apply the modified constructor arguments
to construct an object of type T as a return value or in-place, respectively[.](#3.sentence-3)
[*Note [1](#note-1)*:
For uses_allocator_construction_args andmake_obj_using_allocator, type T is not deduced and must therefore be specified explicitly by the caller[.](#3.sentence-4)
— *end note*]
[🔗](#lib:uses_allocator_construction_args)
`template<class T, class Alloc, class... Args>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
Args&&... args) noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1364)
*Constraints*: remove_cv_t<T> is not a specialization of pair[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1368)
*Returns*: A tuple value determined as follows:
- [(5.1)](#5.1)
If uses_allocator_v<remove_cv_t<T>, Alloc> is false and is_constructible_v<T, Args...> is true,
return forward_as_tuple(std::forward<Args>(args)...)[.](#5.1.sentence-1)
- [(5.2)](#5.2)
Otherwise, if uses_allocator_v<remove_cv_t<T>, Alloc> is true and is_constructible_v<T, allocator_arg_t, const Alloc&, Args...> is true,
returntuple<allocator_arg_t, const Alloc&, Args&&...>( allocator_arg, alloc, std::forward<Args>(args)...)
- [(5.3)](#5.3)
Otherwise, if uses_allocator_v<remove_cv_t<T>, Alloc> is true and is_constructible_v<T, Args..., const Alloc&> is true,
return forward_as_tuple(std::forward<Args>(args)..., alloc)[.](#5.3.sentence-1)
- [(5.4)](#5.4)
Otherwise, the program is ill-formed[.](#5.4.sentence-1)
[*Note [2](#note-2)*:
This definition prevents a silent failure
to pass the allocator to a constructor of a type for whichuses_allocator_v<T, Alloc> is true[.](#5.sentence-2)
— *end note*]
[🔗](#lib:uses_allocator_construction_args_)
`template<class T, class Alloc, class Tuple1, class Tuple2>
constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
Tuple1&& x, Tuple2&& y) noexcept;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1407)
Let T1 be T::first_type[.](#6.sentence-1)
Let T2 be T::second_type[.](#6.sentence-2)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1411)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1415)
*Effects*: Equivalent to:return make_tuple( piecewise_construct,
apply([&alloc](auto&&... args1) {return uses_allocator_construction_args<T1>( alloc, std::forward<decltype(args1)>(args1)...); }, std::forward<Tuple1>(x)),
apply([&alloc](auto&&... args2) {return uses_allocator_construction_args<T2>( alloc, std::forward<decltype(args2)>(args2)...); }, std::forward<Tuple2>(y)));
[🔗](#lib:uses_allocator_construction_args__)
`template<class T, class Alloc>
constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1439)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1443)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
tuple<>{}, tuple<>{});
[🔗](#lib:uses_allocator_construction_args___)
`template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
U&& u, V&& v) noexcept;
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1460)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1464)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(std::forward<U>(u)),
forward_as_tuple(std::forward<V>(v)));
[🔗](#lib:uses_allocator_construction_args____)
`template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
pair<U, V>& pr) noexcept;
template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
const pair<U, V>& pr) noexcept;
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1485)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1489)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(pr.first),
forward_as_tuple(pr.second));
[🔗](#lib:uses_allocator_construction_args_____)
`template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
pair<U, V>&& pr) noexcept;
template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
const pair<U, V>&& pr) noexcept;
`
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1510)
*Constraints*: remove_cv_t<T> is a specialization of pair[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1514)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(get<0>(std::move(pr))),
forward_as_tuple(get<1>(std::move(pr))));
[🔗](#lib:uses_allocator_construction_args______)
`template<class T, class Alloc, [pair-like](tuple.syn#concept:pair-like "22.4.2Header <tuple> synopsis[tuple.syn]") P>
constexpr auto uses_allocator_construction_args(const Alloc& alloc, P&& p) noexcept;
`
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1531)
*Constraints*: remove_cv_t<T> is a specialization of pair andremove_cvref_t<P> is not a specialization of ranges::subrange[.](#17.sentence-1)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1536)
*Effects*: Equivalent to:return uses_allocator_construction_args<T>(alloc, piecewise_construct,
forward_as_tuple(get<0>(std::forward<P>(p))),
forward_as_tuple(get<1>(std::forward<P>(p))));
[🔗](#lib:uses_allocator_construction_args_______)
`template<class T, class Alloc, class U>
constexpr auto uses_allocator_construction_args(const Alloc& alloc, U&& u) noexcept;
`
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1553)
Let *FUN* be the function template:template<class A, class B>void *FUN*(const pair<A, B>&);
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1560)
*Constraints*: remove_cv_t<T> is a specialization of pair, and either:
- [(20.1)](#20.1)
remove_cvref_t<U> is a specialization of ranges::subrange, or
- [(20.2)](#20.2)
U does not satisfy [*pair-like*](tuple.syn#concept:pair-like "22.4.2Header <tuple> synopsis[tuple.syn]") and
the expression *FUN*(u) is not well-formed
when considered as an unevaluated operand[.](#20.sentence-1)
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1572)
Let *pair-constructor* be an exposition-only class defined as follows:class *pair-constructor* {using *pair-type* = remove_cv_t<T>; // *exposition only*constexpr auto *do-construct*(const *pair-type*& p) const { // *exposition only*return make_obj_using_allocator<*pair-type*>(*alloc_*, p); }constexpr auto *do-construct*(*pair-type*&& p) const { // *exposition only*return make_obj_using_allocator<*pair-type*>(*alloc_*, std::move(p)); }const Alloc& *alloc_*; // *exposition only* U& *u_*; // *exposition only*public:constexpr operator *pair-type*() const {return *do-construct*(std::forward<U>(*u_*)); }};
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1595)
*Returns*: make_tuple(pc),
where pc is a *pair-constructor* object
whose *alloc_* member is initialized with alloc and
whose *u_* member is initialized with u[.](#22.sentence-1)
[🔗](#lib:make_obj_using_allocator)
`template<class T, class Alloc, class... Args>
constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args);
`
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1610)
*Effects*: Equivalent to:return make_from_tuple<T>(uses_allocator_construction_args<T>( alloc, std::forward<Args>(args)...));
[🔗](#lib:uninitialized_construct_using_allocator)
`template<class T, class Alloc, class... Args>
constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args);
`
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1626)
*Effects*: Equivalent to:return apply([&]<class... U>(U&&... xs) {return construct_at(p, std::forward<U>(xs)...); }, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));

Some files were not shown because too many files have changed in this diff Show More