Constrained algorithms and algorithms on ranges(C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constrained algorithms, e.g.ranges::copy,ranges::sort, ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Execution policies(C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Operations on uninitialized memory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
std::ranges
Non-modifying sequence operations | |||||||||||||||||||||||||||||||||
Modifying sequence operations | |||||||||||||||||||||||||||||||||
Partitioning operations | |||||||||||||||||||||||||||||||||
Sorting operations | |||||||||||||||||||||||||||||||||
Binary search operations (on sorted ranges) | |||||||||||||||||||||||||||||||||
Set operations (on sorted ranges) | |||||||||||||||||||||||||||||||||
Heap operations | |||||||||||||||||||||||||||||||||
Minimum/maximum operations | |||||||||||||||||||||||||||||||||
Permutation operations | |||||||||||||||||||||||||||||||||
Fold operations | |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
Operations on uninitialized storage | |||||||||||||||||||||||||||||||||
Return types | |||||||||||||||||||||||||||||||||
Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Defined in header <numeric> | ||
Call signature | ||
template<std::input_or_output_iterator O,std::sentinel_for<O> S, std::weakly_incrementable T> | (1) | (since C++23) |
template<std::weakly_incrementable T,ranges::output_range<const T&> R> constexpr iota_result<ranges::borrowed_iterator_t<R>, T> | (2) | (since C++23) |
Helper types | ||
template<class O,class T> using iota_result=ranges::out_value_result<O, T>; | (3) | (since C++23) |
Fills the range[
first,
last)
with sequentially increasing values, starting withvalue and repetitively evaluating++value.
Equivalent operation:
*(first)= value;*(first+1)=++value;*(first+2)=++value;*(first+3)=++value;...
Contents |
first, last | - | the iterator-sentinel pair defining therange of elements to fill with sequentially increasing values starting withvalue |
value | - | initial value to store; the expression++value must be well-formed |
{last, value+ranges::distance(first, last)}
Exactlylast- first increments and assignments.
struct iota_fn{template<std::input_or_output_iterator O,std::sentinel_for<O> S,std::weakly_incrementable T> requiresstd::indirectly_writable<O,const T&>constexpr iota_result<O, T> operator()(O first, S last, T value)const{while(first!= last){*first= as_const(value);++first;++value;}return{std::move(first), std::move(value)};} template<std::weakly_incrementable T, std::ranges::output_range<const T&> R>constexpr iota_result<std::ranges::borrowed_iterator_t<R>, T> operator()(R&& r, T value)const{return(*this)(std::ranges::begin(r), std::ranges::end(r), std::move(value));}}; inlineconstexpr iota_fn iota; |
The function is named after the integer function⍳ from the programming languageAPL.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_ranges_iota | 202202L | (C++23) | std::ranges::iota |
Uses thevector of iterators (std::vector<std::list<T>::iterator>) as a proxy to shuffle the elements of thestd::list, becauseranges::shuffle cannot be applied to thestd::list directly.
#include <algorithm>#include <functional>#include <iostream>#include <list>#include <numeric>#include <random>#include <vector> template<typename Proj=std::identity>void println(auto comment, std::ranges::input_rangeauto&& range, Proj proj={}){for(std::cout<< comment;autoconst&element: range)std::cout<< proj(element)<<' ';std::cout<<'\n';} int main(){std::list<int> list(8); // Fill the list with ascending values: 0, 1, 2, ..., 7 std::ranges::iota(list,0); println("List: ", list); // A vector of iterators (see the comment to Example)std::vector<std::list<int>::iterator> vec(list.size()); // Fill with iterators to consecutive list's elements std::ranges::iota(vec.begin(), vec.end(), list.begin()); std::ranges::shuffle(vec,std::mt19937{std::random_device{}()}); println("List viewed via vector: ", vec,[](auto it){return*it;});}
Possible output:
List: 0 1 2 3 4 5 6 7List viewed via vector: 5 7 6 0 1 3 4 2
copy-assigns the given value to every element in a range (function template)[edit] | |
(C++20) | assigns a range of elements a certain value (algorithm function object)[edit] |
assigns the results of successive function calls to every element in a range (function template)[edit] | |
(C++20) | saves the result of a function in a range (algorithm function object)[edit] |
(C++20) | aview consisting of a sequence generated by repeatedly incrementing an initial value(class template)(customization point object)[edit] |
(C++11) | fills a range with successive increments of the starting value (function template)[edit] |