adjacent_filtered lets the first element entry through
- Dominant language
- C++
- Stars
- 45
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
Following on from [Trac#13203](https://svn.boost.org/trac10/ticket/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](https://www.boost.org/doc/libs/1_68_0/libs/range/doc/html/range/reference/adaptors/reference/adjacent_filtered.html#range.reference.adaptors.reference.adjacent_filtered):
> For all adjacent elements [x,y] in the returned range, bi_pred(x,y) is true.
Eg:
~~~cpp
int main() {
const std::vector 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:
~~~no-highlight
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.