C++ 20 introduces std::ranges::iota_view
.
It may be used as part of a for
loop, for example.
for (auto i: std::ranges::iota_view(0, 10))
It appears to take two template parameters. For example, the following will compile.
std::ranges::iota_view<int64_t, int64_t>(0, 10)
The first template parameter is W
which should be std::weakly_incrementable
. The second template parameter is Bound
which should be std::semiregular
.
What is the purpose of these two template parameters? Can they be used to control the type returned by iota_view
?
In other words, what effect, if any, do they have on the deduced type of auto i
in the example above?
C++ 20 introduces std::ranges::iota_view
.
It may be used as part of a for
loop, for example.
for (auto i: std::ranges::iota_view(0, 10))
It appears to take two template parameters. For example, the following will compile.
std::ranges::iota_view<int64_t, int64_t>(0, 10)
The first template parameter is W
which should be std::weakly_incrementable
. The second template parameter is Bound
which should be std::semiregular
.
What is the purpose of these two template parameters? Can they be used to control the type returned by iota_view
?
In other words, what effect, if any, do they have on the deduced type of auto i
in the example above?
1 Answer
Reset to default 6https://en.cppreference/w/cpp/ranges/iota_view <- we start at template<W, Bound> class iota_view
.
Its iterator is std::ranges::iota_view<W, Bound>::iterator
And operator *
on this iterator returns a value of type W
. So the value type for the for
loop is controlled by the first template parameter.
The Bound
type is checked to be comparable ("weakly-equality-comparable-with") with W
.
std::ranges::iota_view(int64_t(0), 10)
– Jarod42 Commented Feb 14 at 14:39