dimanche 25 février 2018

Why can't I dereference the result iterator when ranges::find_if takes an infinite range as rvalue?

Let

auto empty_line = [](auto& str){ return str.size() == 0; };

Now, we can do this:

auto line_range_with_first_non_empty = 
                ranges::view::drop_while(ranges::getlines(std::cin),empty_line);
auto input1 = std::stoi(*line_range_with_first_non_empty.begin());

We also can do this:

auto line_range2 = ranges::getlines(std::cin);
auto iter2 = ranges::find_if_not(line_range2,empty_line);
auto input2 = std::stoi(*iter2);

Unfortunately, when I try to shorten version above...

auto iter3 = ranges::find_if_not(ranges::getlines(std::cin),empty_line);
// Error when deref.
// auto input3 = std::stoi(*iter3);

Why can't I dereference when ranges::find_if takes an infinite range as rvalue?

godbolt.org/g/BZkT72

Aucun commentaire:

Enregistrer un commentaire