adjacent_filtered always lets the first element of the range leak through before it starts the real filtering. This means it's easy to get it to violate its stated postcondition:
For all adjacent elements [x,y] in the returned range, bi_pred(x,y) is true.
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.
Following on from Trac#13203…
adjacent_filtered
always lets the first element of the range leak through before it starts the real filtering. This means it's easy to get it to violate its stated postcondition:Eg:
…outputs:
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.