std::iota
Актуально для C++23.
#include <algorithm>
Актуально на 2024-02-16.
Define overload #1
template<class ForwardIterator, class T>
constexpr
void iota(ForwardIterator first, ForwardIterator last, T value);
template<class ForwardIterator, class T>
constexpr
void iota(ForwardIterator first, ForwardIterator last, T value);
template<class ForwardIterator, class T> constexpr void iota(ForwardIterator first, ForwardIterator last, T value);
Заполнит последовательность [first, last] значением value, инкрементируя его после каждого присваивания.
Example, possible implementation
Examples
Example 1:
#include <iostream>
#include <numeric>
#include <vector>
int main()
{
std::vector<int> v;
v.resize(5, 0);
std::iota(std::begin(v), std::end(v), 0);
for (auto el : v)
std::cout << el << std::endl;
return 0;
}
#include <iostream>
#include <numeric>
#include <vector>
int main()
{
std::vector<int> v;
v.resize(5, 0);
std::iota(std::begin(v), std::end(v), 0);
for (auto el : v)
std::cout << el << std::endl;
return 0;
}
#include <iostream> #include <numeric> #include <vector> int main() { std::vector<int> v; v.resize(5, 0); std::iota(std::begin(v), std::end(v), 0); for (auto el : v) std::cout << el << std::endl; return 0; }
0
1
2
3
4
0
1
2
3
4
0 1 2 3 4
Changelog
C++26
TODOC++23
TODOC++20
TODOC++17
TODOC++14
TODOC++11
TODOSee also
TODO
This page was last modified on 2024-02-16