最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - How do I control the type of value returned by std::ranges::iota_view? - Stack Overflow

programmeradmin2浏览0评论

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?

Share Improve this question edited Feb 14 at 14:34 Jarod42 218k15 gold badges194 silver badges327 bronze badges asked Feb 14 at 14:07 user2138149user2138149 17.2k30 gold badges145 silver badges287 bronze badges 1
  • 2 Notice you might do std::ranges::iota_view(int64_t(0), 10) – Jarod42 Commented Feb 14 at 14:39
Add a comment  | 

1 Answer 1

Reset to default 6

https://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.

发布评论

评论列表(0)

  1. 暂无评论