tcbrindle / flux

A C++20 library for sequence-orientated programming
https://tristanbrindle.com/flux/
Boost Software License 1.0
472 stars 29 forks source link

filter_adaptor should wrap its underlying cursor #107

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

Currently filter_adaptor uses the same cursor type as its parent sequence, unmodified. This works fine, but can lead to odd situations where using a parent cursor (such as an integer index for a vector, say) on the filtered sequence appears to "ignore" the filter:

std::vector vals{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

auto filtered = flux::ref(vals).filter(flux::pred::even);

std::cout << filtered[0] << std::endl; // prints 1 ?!

Godbolt

To avoid this, filter_adaptor should wrap its underlying cursor as something like

struct cursor_type {
    cursor_t<Base> base_cur;
};

to turn the last line above into a compile error.