Daily bit(e) of C++ | std::views::as_const
Daily bit(e) of C++ #155, The C++23 "make the view immutable" view: std::views::as_const.
One downside of standard views is their behaviour when marked as const.
As is typical with reference types, views do not respect const. Unfortunately, on top of that, certain combinations of views and ranges require mutability.
With the C++23 std::views::as_const, we can leave the views mutable while enforcing the immutability of the underlying data.
I love as_const. I learned it from a QT book.