["c++","python"]
Is there a compact equivalent to Python range() in C++/STL

How can I do the equivalent of the following using C++/STL? I want to fill a std::vector with a range of values [min, max). # Python >>> x = range(0, 10) >>> x [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] I suppose I could use std::generate_n and provide a functor to generate the sequence, but I was wondering if there is a more succinct way of doing this using STL?
In C++11, there's std::iota: #include <vector> #include <numeric> //std::iota int main() { std::vector<int> x(10); std::iota(std::begin(x), std::end(x), 0); //0 is the starting number } C++20 introduced a lazy version (just like Python) as part of the ranges library: #include <iostream> #include <ranges> namespace views = std::views; int main() { for (int x : views::iota(0, 10)) { std::cout << x << ' '; // 0 1 2 3 4 5 6 7 8 9 } }