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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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> | ||
template<class ForwardIt,class T> void iota( ForwardIt first, ForwardIt last, T value); | (since C++11) (constexpr since C++20) | |
Fills the range[
first,
last)
with sequentially increasing values, starting withvalue and repetitively evaluating++value.
Equivalent operation (assuming++value returns the incremented value):
*first= value;*++first=++value;*++first=++value;*++first=++value;// repeats until “last” is reached
If any of the following conditions is satisfied, the program is ill-formed:
T
is not convertible to thevalue type ofForwardIt
.T
.Contents |
first, last | - | the pair of iterators defining therange of elements to fill with sequentially increasing values starting withvalue |
value | - | initial value to store |
Exactlystd::distance(first, last) increments and assignments.
template<class ForwardIt,class T>constexpr// since C++20void iota(ForwardIt first, ForwardIt last, T value){for(; first!= last;++first,++value)*first= value;} |
The function is named after the integer function⍳ from the programming languageAPL. It was one of theSTL components that were not included in C++98, but made it into the standard library in C++11.
The following example appliesstd::shuffle to avector ofstd::lists' iterators.std::iota
is used to populate containers.
#include <algorithm>#include <iomanip>#include <iostream>#include <list>#include <numeric>#include <random>#include <vector> class BigData// inefficient to copy{int data[1024];/* some raw data */public:explicit BigData(int i=0){ data[0]= i;/* ... */} operatorint()const{return data[0];} BigData& operator=(int i){ data[0]= i;return*this;}/* ... */}; int main(){std::list<BigData> l(10); std::iota(l.begin(), l.end(),-4); std::vector<std::list<BigData>::iterator> v(l.size()); std::iota(v.begin(), v.end(), l.begin());// Vector of iterators (to original data) is used to avoid expensive copying,// and because std::shuffle (below) cannot be applied to a std::list directly. std::shuffle(v.begin(), v.end(),std::mt19937{std::random_device{}()}); std::cout<<"Original contents of the list l:\t";for(constauto& n: l)std::cout<<std::setw(2)<< n<<' ';std::cout<<'\n'; std::cout<<"Contents of l, viewed via shuffled v:\t";for(constauto i: v)std::cout<<std::setw(2)<<*i<<' ';std::cout<<'\n';}
Possible output:
Original contents of the list l:-4 -3 -2 -1 0 1 2 3 4 5Contents of l, viewed via shuffled v:-1 5 -4 0 2 1 4 -2 3 -3
(C++23) | fills a range with successive increments of the starting value (algorithm function object)[edit] |
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] |
aview that maps each element of adapted sequence to a tuple of both the element's position and its value(class template)(range adaptor object)[edit] |