Init
This commit is contained in:
87
cppdraft/alg/adjacent/find.md
Normal file
87
cppdraft/alg/adjacent/find.md
Normal 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity,
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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
56
cppdraft/alg/all/of.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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
57
cppdraft/alg/any/of.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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)
|
||||
260
cppdraft/alg/binary/search.md
Normal file
260
cppdraft/alg/binary/search.md
Normal 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other 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.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other 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.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other 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.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other 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.3 Indirect 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)
|
||||
27
cppdraft/alg/binary/search/general.md
Normal file
27
cppdraft/alg/binary/search/general.md
Normal 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.4 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[.](#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
49
cppdraft/alg/c/library.md
Normal 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.2 Header <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.14 Restrictions on exception handling"))[.](#4.sentence-1)
|
||||
|
||||
See also: ISO/IEC 9899:2024, 7.24.5
|
||||
57
cppdraft/alg/clamp.md
Normal file
57
cppdraft/alg/clamp.md
Normal 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.3 Indirect 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.2 Template 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
87
cppdraft/alg/contains.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<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.3 Indirect 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.6 Other 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1,
|
||||
[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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
401
cppdraft/alg/copy.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.9 Concept input_iterator [iterator.concept.input]") I, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O,
|
||||
[sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR,
|
||||
class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.13 Concept 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.8 Requirements 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_iterator [iterator.concept.bidir]") I2>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.6 Other range refinements [range.refinements]") R, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_iterator [iterator.concept.bidir]") I>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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
106
cppdraft/alg/count.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<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.3 Indirect 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.6 Other 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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
102
cppdraft/alg/ends/with.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.11 Concept forward_iterator [iterator.concept.forward]")<I1> || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<S1, I1>) &&
|
||||
([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]")<I2> || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<S2, I2>) &&
|
||||
[indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other 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.6 Other range refinements [range.refinements]")<R1> || [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<R1>) &&
|
||||
([forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]")<R2> || [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<R2>) &&
|
||||
[indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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
130
cppdraft/alg/equal.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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.7 Random access iterators [random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random 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.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]") ([[iterator.concept.sizedsentinel]](iterator.concept.sizedsentinel "24.3.4.8 Concept 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.4 Sized 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
78
cppdraft/alg/fill.md
Normal 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.7 Concept 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.10 Concept 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.6 Other 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.10 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class T = range_value_t<R>>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept 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.3 Concept 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.1 General")) to the output iterator[.](#2.sentence-1)
|
||||
|
||||
The type Size is convertible
|
||||
to an integral type ([[conv.integral]](conv.integral "7.3.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#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
128
cppdraft/alg/find.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<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.3 Indirect 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.6 Other 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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
112
cppdraft/alg/find/end.md
Normal 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.11 Concept forward_iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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)
|
||||
102
cppdraft/alg/find/first/of.md
Normal file
102
cppdraft/alg/find/first/of.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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
93
cppdraft/alg/find/last.md
Normal 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R,
|
||||
class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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
143
cppdraft/alg/fold.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>,
|
||||
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <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.6 Other range refinements [range.refinements]") R, class T = range_value_t<R>,
|
||||
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S,
|
||||
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <algorithm> synopsis [algorithm.syn]")<iter_value_t<I>, I> F>
|
||||
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept 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.6 Other range refinements [range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <algorithm> synopsis [algorithm.syn]")<range_value_t<R>, iterator_t<R>> F>
|
||||
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.4 Header <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.6 Other range refinements [range.refinements]") R, class T = range_value_t<R>,
|
||||
[indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4 Header <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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S,
|
||||
[indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4 Header <algorithm> synopsis [algorithm.syn]")<iter_value_t<I>, I> F>
|
||||
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept 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.6 Other range refinements [range.refinements]") R,
|
||||
[indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4 Header <algorithm> synopsis [algorithm.syn]")<range_value_t<R>, iterator_t<R>> F>
|
||||
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>,
|
||||
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <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.6 Other range refinements [range.refinements]") R, class T = range_value_t<R>,
|
||||
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S,
|
||||
[indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <algorithm> synopsis [algorithm.syn]")<iter_value_t<I>, I> F>
|
||||
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept 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.6 Other range refinements [range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header <algorithm> synopsis [algorithm.syn]")<range_value_t<R>, iterator_t<R>> F>
|
||||
requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept 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
435
cppdraft/alg/foreach.md
Normal 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.2 Template 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.2 Template 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.2 Template 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.3 Effect 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect 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.14 Concept copy_constructible [concept.copyconstructible]")[.](#15.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#itemdecl:4)
|
||||
|
||||
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity,
|
||||
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect 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.3 Effect 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.2 Requirements 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.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#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.2 Template 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.2 Template 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.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#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.2 Template 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.3 Effect 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.9 Concept input_iterator [iterator.concept.input]") I, class Proj = identity,
|
||||
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect 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.14 Concept copy_constructible [concept.copyconstructible]")[.](#34.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#itemdecl:8)
|
||||
|
||||
`template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, class Proj = identity,
|
||||
[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect 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.3 Effect 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.2 Requirements 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
50
cppdraft/alg/func/obj.md
Normal 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.4 Algorithm function objects [alg.func.obj]") is
|
||||
a customization point object ([[customization.point.object]](customization.point.object "16.3.3.3.5 Customization 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.4 Argument-dependent name lookup"))[.](#2.sentence-3)
|
||||
|
||||
When found by unqualified name lookup ([[basic.lookup.unqual]](basic.lookup.unqual "6.5.3 Unqualified name lookup"))
|
||||
for the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") in a function call ([[expr.call]](expr.call "7.6.1.3 Function 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
83
cppdraft/alg/generate.md
Normal 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.6 Concept input_or_output_iterator [iterator.concept.iterator]") O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<O> S, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.14 Concept copy_constructible [concept.copyconstructible]") F>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [output_range](range.refinements#concept:output_range "25.4.6 Other 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.6 Concept input_or_output_iterator [iterator.concept.iterator]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> S,
|
||||
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#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.2 Requirements on user-provided function objects"))[.](#6.sentence-1)
|
||||
417
cppdraft/alg/heap/operations.md
Normal file
417
cppdraft/alg/heap/operations.md
Normal 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.1 General [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[âiâ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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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)
|
||||
37
cppdraft/alg/heap/operations/general.md
Normal file
37
cppdraft/alg/heap/operations/general.md
Normal 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.1 General [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[âiâ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)
|
||||
127
cppdraft/alg/is/permutation.md
Normal file
127
cppdraft/alg/is/permutation.md
Normal 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.11 Concept forward_iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]") I2,
|
||||
[sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R2,
|
||||
class Proj1 = identity, class Proj2 = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect 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.8 Concept 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.8 Concept 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.4 Sized 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)
|
||||
114
cppdraft/alg/lex/comparison.md
Normal file
114
cppdraft/alg/lex/comparison.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect 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
280
cppdraft/alg/merge.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I2> S2,
|
||||
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I2> S2,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.7 Concept 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.8 Requirements 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.8 Requirements for stable algorithms [algorithm.stable]")[.](#12.sentence-1)
|
||||
|
||||
[ð](#itemdecl:3)
|
||||
|
||||
`template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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
465
cppdraft/alg/min/max.md
Normal 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.3 Indirect 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.2 Template 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.6 Object concepts [concepts.object]") T, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.3 Concept 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.2 Template argument requirements [utility.arg.requirements]") requirements[.](#5.sentence-2)
|
||||
|
||||
For the first form, T meets the [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2 Template 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.3 Indirect 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.2 Template 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.6 Object concepts [concepts.object]") T, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.3 Concept 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.2 Template argument requirements [utility.arg.requirements]") requirements[.](#13.sentence-2)
|
||||
|
||||
For the first form, T meets the [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2 Template 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.3 Indirect 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.2 Template 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.6 Object concepts [concepts.object]") T, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.3 Concept 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.2 Template 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.2 Template 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R,
|
||||
class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R,
|
||||
class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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
128
cppdraft/alg/mismatch.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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)
|
||||
2713
cppdraft/alg/modifying/operations.md
Normal file
2713
cppdraft/alg/modifying/operations.md
Normal file
File diff suppressed because it is too large
Load Diff
230
cppdraft/alg/move.md
Normal file
230
cppdraft/alg/move.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS>
|
||||
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR>
|
||||
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2 Concept 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_iterator [iterator.concept.bidir]") I2>
|
||||
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2 Concept 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.6 Other range refinements [range.refinements]") R, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_iterator [iterator.concept.bidir]") I>
|
||||
requires [indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2 Concept 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
56
cppdraft/alg/none/of.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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
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
110
cppdraft/alg/nth/element.md
Normal 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")), and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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
429
cppdraft/alg/partitions.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable 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.6 Bidirectional iterators [bidirectional.iterators]") requirements
|
||||
for the overloads in namespace std or
|
||||
models [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O1, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O2,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O1> && [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O1, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O2,
|
||||
class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, O1> &&
|
||||
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O1> OutS1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O2> OutS2,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O1> && [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR2,
|
||||
class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR1>> &&
|
||||
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 General"))
|
||||
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.14 Concept 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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)
|
||||
151
cppdraft/alg/permutation/generators.md
Normal file
151
cppdraft/alg/permutation/generators.md
Normal 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable 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
150
cppdraft/alg/rand.md
Normal 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.2 Header <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.6 Other range refinements [range.refinements]")<R, invoke_result_t<G&>> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.4 Sized 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.10 Concept output_iterator [iterator.concept.output]")<invoke_result_t<G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<O> S>
|
||||
requires [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.6 Other range refinements [range.refinements]")<R, invoke_result_t<D&, G&>> && [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> &&
|
||||
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.4 Sized 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.10 Concept output_iterator [iterator.concept.output]")<invoke_result_t<D&, G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<O> S>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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);
|
||||
13
cppdraft/alg/rand/general.md
Normal file
13
cppdraft/alg/rand/general.md
Normal 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.12 Specialized <random> algorithms") are declared in the header [<random>](rand.synopsis#header:%3crandom%3e "29.5.2 Header <random> synopsis [rand.synopsis]")[.](#1.sentence-1)
|
||||
141
cppdraft/alg/rand/generate.md
Normal file
141
cppdraft/alg/rand/generate.md
Normal 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.6 Other range refinements [range.refinements]")<R, invoke_result_t<G&>> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.4 Sized 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.10 Concept output_iterator [iterator.concept.output]")<invoke_result_t<G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<O> S>
|
||||
requires [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.6 Other range refinements [range.refinements]")<R, invoke_result_t<D&, G&>> && [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> &&
|
||||
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.4 Sized 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.10 Concept output_iterator [iterator.concept.output]")<invoke_result_t<D&, G&>> O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<O> S>
|
||||
requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<D&, G&> && [uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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);
|
||||
106
cppdraft/alg/random/sample.md
Normal file
106
cppdraft/alg/random/sample.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, class Gen>
|
||||
requires ([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]")<I> || [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]")<O>) &&
|
||||
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> &&
|
||||
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, class Gen>
|
||||
requires ([forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]")<R> || [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]")<O>) &&
|
||||
[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.3 Uniform 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.1 General")) 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.3 Input iterators [input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3 Input iterators"))[.](#2.1.sentence-1)
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
SampleIterator meets
|
||||
the [*Cpp17OutputIterator*](output.iterators#:Cpp17OutputIterator "24.3.5.4 Output iterators [output.iterators]") requirements ([[output.iterators]](output.iterators "24.3.5.4 Output iterators"))[.](#2.2.sentence-1)
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
SampleIterator meets
|
||||
the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7 Random access iterators [random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators"))
|
||||
unless PopulationIterator models [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]") ([[iterator.concept.forward]](iterator.concept.forward "24.3.4.11 Concept forward_iterator"))[.](#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.3 Uniform 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.12 Sample [alg.random.sample]"))
|
||||
from [first, last) (the [*population*](#def:population "26.7.12 Sample [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.11 Concept 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.11 Concept 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)
|
||||
68
cppdraft/alg/random/shuffle.md
Normal file
68
cppdraft/alg/random/shuffle.md
Normal 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Gen>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<I> &&
|
||||
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.6 Other range refinements [range.refinements]") R, class Gen>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> &&
|
||||
[uniform_random_bit_generator](rand.req.urng#concept:uniform_random_bit_generator "29.5.3.3 Uniform 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable 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.3 Uniform 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
339
cppdraft/alg/remove.md
Normal 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.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other 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.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.2 Template 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.8 Requirements 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, O> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS,
|
||||
class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR,
|
||||
class Proj = identity,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 General")) 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.13 Concept 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.8 Requirements for stable algorithms"))[.](#15.sentence-1)
|
||||
309
cppdraft/alg/replace.md
Normal file
309
cppdraft/alg/replace.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<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.3 Concept indirectly_writable [iterator.concept.writable]")<I, const T2&> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.6 Other 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.3 Concept indirectly_writable [iterator.concept.writable]")<iterator_t<R>, const T2&> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Concept indirectly_writable [iterator.concept.writable]")<I, const T2&> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Concept indirectly_writable [iterator.concept.writable]")<iterator_t<R>, const T2&> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
class T = projected_value_t<I, Proj>,
|
||||
[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.6 Other 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.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 General")) 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<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.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*> &&
|
||||
[output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept 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.6 Other 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, O> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
|
||||
&& [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*> &&
|
||||
[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>> &&
|
||||
[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to,
|
||||
projected<iterator_t<R>, Proj>, const T1*> &&
|
||||
[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<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.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> && [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept 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.6 Other 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.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, O> && [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> && [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, iterator_t<OutR>> &&
|
||||
[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 General")) 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
166
cppdraft/alg/req.md
Normal 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.2 Concept indirectly_readable [iterator.concept.readable]") and [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]") types:[indirectly_movable](#concept:indirectly_movable "24.3.7.2 Concept indirectly_movable [alg.req.ind.move]"),[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]"), and[indirectly_swappable](#concept:indirectly_swappable "24.3.7.4 Concept indirectly_swappable [alg.req.ind.swap]")[.](#general-1.sentence-3)
|
||||
|
||||
There are three relational concepts for rearrangements:[permutable](#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]"),[mergeable](#concept:mergeable "24.3.7.7 Concept mergeable [alg.req.mergeable]"), and[sortable](#concept:sortable "24.3.7.8 Concept 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.5 Concept 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.9 Concept-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.2 Concept indirectly_movable [alg.req.ind.move]") concept specifies the relationship between
|
||||
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.2 Concept indirectly_movable [alg.req.ind.move]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.2 Concept indirectly_movable [alg.req.ind.move]") concept augments[indirectly_movable](#concept:indirectly_movable "24.3.7.2 Concept 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.2 Concept 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.2 Concept indirectly_movable [alg.req.ind.move]") =[indirectly_movable](#concept:indirectly_movable "24.3.7.2 Concept indirectly_movable [alg.req.ind.move]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, iter_value_t<In>> &&[movable](concepts.object#concept:movable "18.6 Object concepts [concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_from [concept.constructible]")<iter_value_t<In>, iter_rvalue_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8 Concept 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.2 Concept 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.17 Moved-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.3 Concept indirectly_copyable [alg.req.ind.copy]") concept specifies the relationship between
|
||||
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]") concept augments[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3 Concept 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.2 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]") =[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, const iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, iter_value_t<In>&&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, const iter_value_t<In>&&> &&[copyable](concepts.object#concept:copyable "18.6 Object concepts [concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_from [concept.constructible]")<iter_value_t<In>, iter_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8 Concept 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.3 Concept 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.17 Moved-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.4 Concept 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.2 Concept 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.4 Concept indirectly_swappable [alg.req.ind.swap]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]")<I1> && [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept 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.5 Concept 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.5 Concept indirectly_comparable [alg.req.ind.cmp]") =[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect 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.6 Concept 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.6 Concept permutable [alg.req.permutable]") =[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]")<I> &&[indirectly_movable_storable](#concept:indirectly_movable_storable "24.3.7.2 Concept indirectly_movable [alg.req.ind.move]")<I, I> &&[indirectly_swappable](#concept:indirectly_swappable "24.3.7.4 Concept 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.7 Concept 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.7 Concept mergeable [alg.req.mergeable]") =[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]")<I1> &&[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]")<I2> &&[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]")<Out> &&[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I1, Out> &&[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I2, Out> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.8 Concept 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.8 Concept sortable [alg.req.sortable]") =[permutable](#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<I> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<R, projected<I, P>>;
|
||||
38
cppdraft/alg/req/general.md
Normal file
38
cppdraft/alg/req/general.md
Normal 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.2 Concept indirectly_readable [iterator.concept.readable]") and [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]") types:[indirectly_movable](alg.req.ind.move#concept:indirectly_movable "24.3.7.2 Concept indirectly_movable [alg.req.ind.move]"),[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]"), and[indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept 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.6 Concept permutable [alg.req.permutable]"),[mergeable](alg.req.mergeable#concept:mergeable "24.3.7.7 Concept mergeable [alg.req.mergeable]"), and[sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.5 Concept 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.9 Concept-constrained comparisons"))[.](#2.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
19
cppdraft/alg/req/ind/cmp.md
Normal file
19
cppdraft/alg/req/ind/cmp.md
Normal 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.5 Concept 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.5 Concept indirectly_comparable [alg.req.ind.cmp]") =[indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<R, projected<I1, P1>, projected<I2, P2>>;
|
||||
43
cppdraft/alg/req/ind/copy.md
Normal file
43
cppdraft/alg/req/ind/copy.md
Normal 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.3 Concept indirectly_copyable [alg.req.ind.copy]") concept specifies the relationship between
|
||||
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]") concept augments[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3 Concept 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.2 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]") =[indirectly_copyable](#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, const iter_value_t<In>&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, iter_value_t<In>&&> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, const iter_value_t<In>&&> &&[copyable](concepts.object#concept:copyable "18.6 Object concepts [concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_from [concept.constructible]")<iter_value_t<In>, iter_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8 Concept 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.3 Concept 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.17 Moved-from state of library types"))[.](#3.sentence-3)
|
||||
40
cppdraft/alg/req/ind/move.md
Normal file
40
cppdraft/alg/req/ind/move.md
Normal 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.2 Concept indirectly_movable [alg.req.ind.move]") concept specifies the relationship between
|
||||
an [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]") type and an [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.2 Concept indirectly_movable [alg.req.ind.move]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]")<In> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.2 Concept indirectly_movable [alg.req.ind.move]") concept augments[indirectly_movable](#concept:indirectly_movable "24.3.7.2 Concept 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.2 Concept 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.2 Concept indirectly_movable [alg.req.ind.move]") =[indirectly_movable](#concept:indirectly_movable "24.3.7.2 Concept indirectly_movable [alg.req.ind.move]")<In, Out> &&[indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept indirectly_writable [iterator.concept.writable]")<Out, iter_value_t<In>> &&[movable](concepts.object#concept:movable "18.6 Object concepts [concepts.object]")<iter_value_t<In>> &&[constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_from [concept.constructible]")<iter_value_t<In>, iter_rvalue_reference_t<In>> &&[assignable_from](concept.assignable#concept:assignable_from "18.4.8 Concept 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.2 Concept 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.17 Moved-from state of library types"))[.](#3.sentence-3)
|
||||
21
cppdraft/alg/req/ind/swap.md
Normal file
21
cppdraft/alg/req/ind/swap.md
Normal 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.4 Concept 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.2 Concept indirectly_readable [iterator.concept.readable]") types[.](#1.sentence-1)
|
||||
|
||||
template<class I1, class I2 = I1>concept [indirectly_swappable](#concept:indirectly_swappable "24.3.7.4 Concept indirectly_swappable [alg.req.ind.swap]") =[indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_readable [iterator.concept.readable]")<I1> && [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept 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); };
|
||||
18
cppdraft/alg/req/mergeable.md
Normal file
18
cppdraft/alg/req/mergeable.md
Normal 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.7 Concept 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.7 Concept mergeable [alg.req.mergeable]") =[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]")<I1> &&[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]")<I2> &&[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]")<Out> &&[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I1, Out> &&[indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I2, Out> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<R, projected<I1, P1>, projected<I2, P2>>;
|
||||
18
cppdraft/alg/req/permutable.md
Normal file
18
cppdraft/alg/req/permutable.md
Normal 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.6 Concept 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.6 Concept permutable [alg.req.permutable]") =[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]")<I> &&[indirectly_movable_storable](alg.req.ind.move#concept:indirectly_movable_storable "24.3.7.2 Concept indirectly_movable [alg.req.ind.move]")<I, I> &&[indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept indirectly_swappable [alg.req.ind.swap]")<I, I>;
|
||||
18
cppdraft/alg/req/sortable.md
Normal file
18
cppdraft/alg/req/sortable.md
Normal 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.8 Concept 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.8 Concept sortable [alg.req.sortable]") =[permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<I> &&[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<R, projected<I, P>>;
|
||||
167
cppdraft/alg/reverse.md
Normal file
167
cppdraft/alg/reverse.md
Normal 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<I>
|
||||
constexpr I ranges::reverse(I first, S last);
|
||||
template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable 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.12 Concept bidirectional_iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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
236
cppdraft/alg/rotate.md
Normal 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.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")), and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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
232
cppdraft/alg/search.md
Normal 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.11 Concept forward_iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]") I2,
|
||||
[sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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.2 Template argument requirements [utility.arg.requirements]") requirements[.](#12.sentence-1)
|
||||
698
cppdraft/alg/set/operations.md
Normal file
698
cppdraft/alg/set/operations.md
Normal 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.7 Class 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Indirect 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Indirect 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I2> S2,
|
||||
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I2> S2,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.7 Concept 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.8 Requirements 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I2> S2,
|
||||
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I2> S2,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.7 Concept 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.8 Requirements 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I2> S2,
|
||||
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I2> S2,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.7 Concept 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I2> S2,
|
||||
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I2> S2,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.7 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.7 Concept 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.8 Requirements 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)
|
||||
21
cppdraft/alg/set/operations/general.md
Normal file
21
cppdraft/alg/set/operations/general.md
Normal 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.7 Set 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.7 Class 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
161
cppdraft/alg/shift.md
Normal 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.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.2 Template 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.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.2 Template argument requirements [utility.arg.requirements]") requirements,
|
||||
and ForwardIterator meets
|
||||
the [*Cpp17BidirectionalIterator*](bidirectional.iterators#:Cpp17BidirectionalIterator "24.3.5.6 Bidirectional iterators [bidirectional.iterators]") requirements ([[bidirectional.iterators]](bidirectional.iterators "24.3.5.6 Bidirectional iterators")) or
|
||||
the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3 Swappable 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.12 Concept 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
559
cppdraft/alg/sort.md
Normal 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.8 Requirements 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.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Comp = ranges::less,
|
||||
class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.8 Concept 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
the type of *first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R,
|
||||
class Comp = ranges::less, class Proj = identity>
|
||||
requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<I1, I2> && [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]")<I2, Comp, Proj2> &&
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R1, [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R1>, iterator_t<R2>> &&
|
||||
[sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]")<iterator_t<R2>, Comp, Proj2> &&
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<I1, I2> && [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]")<I2, Comp, Proj2> &&
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R1>, iterator_t<R2>> &&
|
||||
[sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]")<iterator_t<R2>, Comp, Proj2> &&
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 General")) 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.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")),
|
||||
the type of *result_first meets
|
||||
the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template 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.2 Template 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.11 Concept forward_iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.3 Indirect 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_strict_weak_order](indirectcallable.indirectinvocable#concept:indirect_strict_weak_order "24.3.6.3 Indirect 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
3654
cppdraft/alg/sorting.md
Normal file
File diff suppressed because it is too large
Load Diff
116
cppdraft/alg/sorting/general.md
Normal file
116
cppdraft/alg/sorting/general.md
Normal 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.8 Sorting 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.10 Function objects"))
|
||||
that meets the requirements for a template parameter
|
||||
named BinaryPredicate ([[algorithms.requirements]](algorithms.requirements "26.2 Algorithms 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.4 Binary 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)
|
||||
51
cppdraft/alg/starts/with.md
Normal file
51
cppdraft/alg/starts/with.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.5 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept 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.5 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other 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.5 Concept 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
117
cppdraft/alg/swap.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I2> S2>
|
||||
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2>
|
||||
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I2> S2>
|
||||
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2>
|
||||
requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept 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.3 Swappable 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.3 Swappable 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
58
cppdraft/alg/three/way.md
Normal 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
205
cppdraft/alg/transform.md
Normal 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O,
|
||||
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F, class Proj = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F,
|
||||
class Proj = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS,
|
||||
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F, class Proj = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR,
|
||||
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F, class Proj = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.9 Concept input_iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I2> S2,
|
||||
[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F, class Proj1 = identity,
|
||||
class Proj2 = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O,
|
||||
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F, class Proj1 = identity, class Proj2 = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I1> S1,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I2> S2,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS,
|
||||
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F, class Proj1 = identity, class Proj2 = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2,
|
||||
[sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR, [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]") F,
|
||||
class Proj1 = identity, class Proj2 = identity>
|
||||
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3 Concept 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.2 Requirements 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
278
cppdraft/alg/unique.md
Normal 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.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect 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.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
||||
requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept 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.2 Template 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.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept indirectly_copyable [alg.req.ind.copy]")<I, O> &&
|
||||
([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]")<I> ||
|
||||
([input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]")<O> && [same_as](concept.same#concept:same_as "18.4.2 Concept 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.3 Concept 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.6 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_incrementable [iterator.concept.winc]") O, class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect 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.3 Concept indirectly_copyable [alg.req.ind.copy]")<iterator_t<R>, O> &&
|
||||
([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_iterator [iterator.concept.forward]")<iterator_t<R>> ||
|
||||
([input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_iterator [iterator.concept.input]")<O> && [same_as](concept.same#concept:same_as "18.4.2 Concept 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.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,
|
||||
[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<O> OutS, class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to>
|
||||
requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly_copyable "24.3.7.3 Concept 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.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") OutR,
|
||||
class Proj = identity,
|
||||
[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect 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.3 Concept 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.1 General")) 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.11 Concept forward_iterator [iterator.concept.forward]") ([[iterator.concept.forward]](iterator.concept.forward "24.3.4.11 Concept 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.5 Forward 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.2 Template 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.6 Object 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)
|
||||
Reference in New Issue
Block a user