Relative Content

Tag Archive for c++std-ranges

a more explicit type instead of auto for std::ranges::views result

auto is really nice to maintain a single definition and avoid some typing. It’s also necessary for std::ranges::views. However, auto can make code harder to read it’s too far from the defining type (particularly in code review). Replacing it with an explicit type can also validate that the type is what you expect (e.g. before passing it to a templated function and winding up in a world of template error message hurt). There needs to be a balance. Unfortunately, auto is necessary for views (I assume since the type is implementation dependent).

Why are views required to be (move-)assignable?

The std::ranges::view concept in C++23 requires a view to be movable, which includes move-assignability. I understand why we want a view to be move-constructible, but why is the assignment necessary?