![]() |
小眼睛的帽子 · css如何选择相同class下的第一个cla ...· 1 月前 · |
![]() |
仗义的电脑桌 · Python WiFi Example · ...· 1 月前 · |
![]() |
爱旅游的牙膏 · 天狂传说笔趣阁无弹窗(卧朝) - ...· 3 月前 · |
![]() |
严肃的烈酒 · 营口市2022年饶河至盖州线张漠洛跨线桥(引 ...· 5 月前 · |
![]() |
愉快的柚子 · C/C++/Qt 控制台输入输出-CSDN博客· 5 月前 · |
![]() |
温柔的人字拖 · 胡锦涛主席与冰岛格里姆松总统会谈· 5 月前 · |
![]() |
爱喝酒的香瓜 · 20世纪50年代,人民警察因这事开始推行“纠 ...· 7 月前 · |
![]() |
细心的硬币
1 年前 |
Constrained algorithms and algorithms on ranges (C++20) | ||||
Constrained algorithms, e.g. ranges::copy , ranges::sort , ... | ||||
Execution policies (C++17) | ||||
(C++17)
|
||||
(C++17)
(C++17)
(C++17)
(C++20)
|
||||
(C++17)
(C++17)
(C++17)
(C++20)
|
||||
Non-modifying sequence operations | ||||
(C++11)
(C++11)
(C++11)
|
||||
(C++17)
|
||||
(C++11)
|
||||
Modifying sequence operations | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++20)
(C++20)
|
||||
(C++17)
|
||||
(until C++17)
|
||||
(C++11)
|
||||
Partitioning operations | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
Sorting operations | ||||
(C++11)
|
||||
(C++11)
|
||||
Binary search operations | ||||
Set operations (on sorted ranges) | ||||
Heap operations | ||||
(C++11)
|
||||
(C++11)
|
||||
Minimum/maximum operations | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++17)
|
||||
Permutations | ||||
(C++11)
|
||||
Numeric operations | ||||
(C++11)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
Operations on uninitialized storage | ||||
(C++17)
|
||||
(C++11)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++17)
|
||||
(C++20)
|
||||
C library | ||||
Non-modifying sequence operations | ||||
(C++23)
(C++23)
|
||||
(C++23)
(C++23)
(C++23)
|
||||
(C++23)
|
||||
(C++23)
|
||||
Modifying sequence operations | ||||
ranges::copy
ranges::copy_if
|
||||
(C++23)
(C++23)
|
||||
Partitioning operations | ||||
Sorting operations | ||||
Binary search operations | ||||
Set operations (on sorted ranges) | ||||
Heap operations | ||||
Minimum/maximum operations | ||||
Permutations | ||||
Numeric operations | ||||
(C++23)
|
||||
Fold operations | ||||
(C++23)
|
||||
(C++23)
|
||||
(C++23)
|
||||
(C++23)
|
||||
(C++23)
|
||||
Operations on uninitialized storage | ||||
Return types | ||||
(C++23)
|
||||
(C++23)
|
<algorithm>
requires
std::
indirectly_copyable
<
I, O
>
constexpr
copy_result
<
I, O
>
copy
(
I first, S last, O result
)
;
requires
std::
indirectly_copyable
<
ranges::
iterator_t
<
R
>
, O
>
constexpr
copy_result
<
ranges::
borrowed_iterator_t
<
R
>
, O
>
copy
(
R
&&
r, O result
)
;
class
Proj
=
std::
identity
,
std::
indirect_unary_predicate
<
std
::
projected
<
I, Proj
>>
Pred
>
requires
std::
indirectly_copyable
<
I, O
>
constexpr
copy_if_result
<
I, O
>
copy_if
(
I first, S last, O result, Pred pred, Proj proj
=
{
}
)
;
class
Proj
=
std::
identity
,
std::
indirect_unary_predicate
<
std
::
projected
<
ranges::
iterator_t
<
R
>
, Proj
>>
Pred
>
requires
std::
indirectly_copyable
<
ranges::
iterator_t
<
R
>
, O
>
constexpr
copy_if_result
<
ranges::
borrowed_iterator_t
<
R
>
, O
>
copy_if
(
R
&&
r, O result, Pred pred, Proj proj
=
{
}
)
;
Copies the elements in the range, defined by
[
first
,
last
)
, to another range beginning at
result
.
[
first
,
last
)
starting from
first
and proceeding to
last
-
1
. The behavior is undefined if
result
is within the range
[
first
,
last
)
. In this case,
ranges::copy_backward
may be used instead.
The function-like entities described on this page are niebloids , that is:
In practice, they may be implemented as function objects, or with special compiler extensions.
Contents[ edit ] Parameters[ edit ] Return valueA ranges::in_out_result containing an input iterator equal to last and an output iterator past the last element copied. [ edit ] Complexity
1-2)
Exactly
last
-
first
assignments.
3-4)
Exactly
last
-
first
applications of the predicate and projection, between
0
and
last
-
first
assignments (assignment for every element for which predicate returns
true
, dependent on predicate and input data).
[ edit ] Notes
In practice, implementations of
When copying overlapping ranges,
[ edit ] Possible implementationstruct copy_fn template<std::input_iterator I, std::sentinel_for<I> S, std::weakly_incrementable O> requires std::indirectly_copyable<I, O> constexpr ranges::copy_result<I, O> operator()(I first, S last, O result) const for (; first != last; ++first, (void)++result) *result = *first; return {std::move(first), std::move(result)}; template<ranges::input_range R, std::weakly_incrementable O> requires std::indirectly_copyable<ranges::iterator_t<R>, O> constexpr ranges::copy_result<ranges::borrowed_iterator_t<R>, O> operator()(R&& r, O result) const return (*this)(ranges::begin(r), ranges::end(r), std::move(result)); inline constexpr copy_fn copy; |
copy_if
struct copy_if_fn template<std::input_iterator I, std::sentinel_for<I> S, std::weakly_incrementable O, class Proj = std::identity, std::indirect_unary_predicate<std::projected<I, Proj>> Pred> requires std::indirectly_copyable<I, O> constexpr ranges::copy_if_result<I, O> operator()(I first, S last, O result, Pred pred, Proj proj = {}) const for (; first != last; ++first) if (std::invoke(pred, std::invoke(proj, *first))) *result = *first; ++result; return {std::move(first), std::move(result)}; template<ranges::input_range R, std::weakly_incrementable O, class Proj = std::identity, std::indirect_unary_predicate< std::projected<ranges::iterator_t<R>, Proj>> Pred> requires std::indirectly_copyable<ranges::iterator_t<R>, O> constexpr ranges::copy_if_result<ranges::borrowed_iterator_t<R>, O> operator()(R&& r, O result, Pred pred, Proj proj = {}) const return (*this)(ranges::begin(r), ranges::end(r), std::move(result), std::ref(pred), std::ref(proj)); inline constexpr copy_if_fn copy_if; [ edit ] Example
The following code uses
Run this code
#include <algorithm> #include <iostream> #include <iterator> #include <numeric> #include <vector> int main() std::vector<int> source(10); std::iota(source.begin(), source.end(), 0); std::vector<int> destination; std::ranges::copy(source.begin(), source.end(), std::back_inserter(destination)); // or, alternatively, // std::vector<int> destination(source.size()); // std::ranges::copy(source.begin(), source.end(), destination.begin()); // either way is equivalent to // std::vector<int> destination = source; std::cout << "destination contains: "; std::ranges::copy(destination, std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n'; std::cout << "odd numbers in destination are: "; std::ranges::copy_if(destination, std::ostream_iterator<int>(std::cout, " "), [](int x) { return (x % 2) == 1; }); std::cout << '\n'; |
(C++20)
|
copies a range of elements in backwards order
(niebloid) [edit] |
(C++20)
|
creates a copy of a range that is reversed
(niebloid) [edit] |
(C++20)
|
copies a number of elements to a new location
(niebloid) [edit] |
(C++20)
|
assigns a range of elements a certain value
(niebloid) [edit] |
(C++20)
(C++20)
|
copies a range of elements omitting those that satisfy specific criteria
(niebloid) [edit] |
(C++11)
|
copies a range of elements to a new location
(function template) [edit] Toolbox
|
---|