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?
https://en.cppreference.com/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With