@specsoftdev live:.cid.8e17e9b93cabb607 specsoftdev@gmail.com
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
TODO
C++23
TODO
C++20
TODO
C++17
TODO
C++14
TODO
C++11
TODO


See also

TODO

This page was last modified on 2024-02-16