ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 440 forks source link

group_by unexpected behavior #1624

Closed lmglmg closed 3 years ago

lmglmg commented 3 years ago

In this small example:

#include <range/v3/all.hpp>
#include <iostream>

int main() {
    std::vector<int> const v{1,2,2,3,1,2,0,4,5,2};

    using namespace ranges;

    auto rng = v | views::group_by([](int i, int j) { return i <= j; });

    std::cout << rng << '\n';
}

The output is

[[1,2,2,3,1,2],[0,4,5,2]]

I would have expected that the less or equal function is applied to neighboring elements and that the output should be ranges of increasing elements:

[[1,2,2,3],[1,2],[0,4,5],[2]]

What is the expected behavior of group_by method?

Godbolt link: https://godbolt.org/z/747KPdEr7

JohelEGP commented 3 years ago

Works as documented. See https://ericniebler.github.io/range-v3/#autotoc_md8.