Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

weakly_incrementable constraint while using iota_view

To quickly create a for loop similar to python’s for i in range(100), I could do:

for (auto const i : std::views::iota(0, 100))
{ /* ... */ }

However, CLion is warning me to add a std::weakly_incrementable constraint to my auto:

for (std::weakly_incrementable auto const i : std::views::iota(0, 100))
{ /* ... */ }

I know that the starting value of iota_view must be weakly_incrementable, and I would assume that auto i will create an i that is the same type of the starting value.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But is it true? Is it possible for it to create something of a totally different type (not even weakly incrementable)? And can I safely ignore the warning?

>Solution :

Is it possible for it to create something of a totally different type
(not even weakly incrementable)? And can I safely ignore the warning?

According to the synopsis of iota_view in [range.iota.view]:

template<weakly_­incrementable W, semiregular Bound = unreachable_sentinel_t>
class iota_view : public view_interface<iota_view<W, Bound>> {
  //...
};

It is already constrained W must be weakly_incrementable. And since iota_view​::​iterator::operator*() returns the same type as W, you can ignore this warning.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading