0
auto int_v10 = std::vector{8,7,3};
//fail    auto rng2 = int_v10 | std::ranges::take_while_view([](int x) {return x> 5;} ) | std::ranges::views::common;
auto rng2 = int_v10 | std::ranges::views::take_while([](int x) {return x> 5;} ) | std::ranges::views::common;
auto result4 = std::accumulate(rng2.begin(), rng2.end(),0);

std::cout<<"Result4: "<<result4<<'\n';

https://en.cppreference.com/w/cpp/ranges/take_while_view
Why std::ranges::take_while_view result cannot pipe to next code block. and std::ranges::views::take_while can?

康桓瑋
  • 33,481
  • 5
  • 40
  • 90
jian
  • 4,119
  • 1
  • 17
  • 32

1 Answers1

1

take_while_view has only two constructors:

take_while_view() = default;
constexpr take_while_view(V base, Pred pred);

The second constructor needs to accept two parameters, one is base and the other is pred, so you need to struct it like this:

auto rng2 = std::ranges::take_while_view(int_v10, [](int x) {return x > 5;}) 
          | std::ranges::views::common;
康桓瑋
  • 33,481
  • 5
  • 40
  • 90