The following code example is taken from the book
C++23 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2026
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
#include <print>
#include <array>
#include <numeric>
int main()
{
std::array<int, 10> arr{};
// assign values from 1 ascending:
auto res = std::ranges::iota(arr, 1);
std::println("arr: {}", arr);
// assign values from 10 ascending:
auto [end, val] = std::ranges::iota(arr, 10);
std::println("arr: {}", arr);
std::println("returns: end() ({}) and {}", arr.end() == end, val);
}