tcbrindle / flux

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

Non const-iterable reversed sequences hard error when used as a range #143

Closed tcbrindle closed 6 months ago

tcbrindle commented 7 months ago

Non const-iterable reversed sequences are pretty rare, but if you find one and try to use it in a range-for loop (or anything else that calls member begin()) it will hard error.

This is because in checking the constraints for begin() const, it tries to check the return type of sequence_traits<reverse_adaptor>::read_at which returns decltype(auto), meaning the compiler will instantiate the function to find out the return type. Unfortunately, the body of this function calls flux::prev, which then hard errors.

There are a couple of possible solutions, but the easiest is probably to avoid decltype(auto) and instead use decltype(<actual expression>) so we get graceful return type SFINAE.

This is pretty much the same as #47, but with reverse_adaptor rather than zip_adaptor.