Opened 5 years ago

#13203 new Bugs

adjacent_filtered lets the first element entry through

Reported by: Tony Lewis <tonyelewis@…> Owned by: Neil Groves
Milestone: To Be Determined Component: range
Version: Boost Development Trunk Severity: Problem
Keywords: adjacent_filtered, adaptor, range, predicate, leak Cc:

Description

adjacent_filtered always lets the first element of the range leak through, even for a predicate that rejects that element as either argument. Eg.

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

        auto b = a | boost::adaptors::adjacent_filtered( [] (const int &x, const int &y) {
                return ( ( x > 2 ) && ( y > 2 ) );
        } );

        for (const auto &x : b) {
                std::cerr << x << "\n";
        }
}

…outputs:

0
4
5

From what I can see in the code, the predicate is currently only applied in the increment() function, which leaves it too late for the first element to be checked.

Change History (0)

Note: See TracTickets for help on using tickets.