any_view & constant
Why the following code is failed:
#include
int main()
{
std::vector
but if we remove the constant it's compiled
#include
int main()
{
std::vector
https://godbolt.org/z/sTKGev
It looks inconsistent with other ranges i.e.
#include
int main()
{
std::vector
https://godbolt.org/z/EnKafK
Hi @sergegers,
there is no requirement that all ranges are "const-iterable", i.e. that that range offers a const version of the begin/end functions. For example the filters view, see https://eel.is/c++draft/range.filter#view. It is perfectly legal to write a view that returns an (iterator, sentinel) pair that changes the state of the view itself.
Any-view needs to handle the weakest guarantee any given range has. One could argue whether to add the property "const-iterable" to ranges::category (like ranges::category::sized does enable the sized-ness property) and support const views if the underlying view is "const-iterable", but I'm not too sure if that would be useful.
@marehr So, the popular idioms - view like a couple of iterators or view introduces a new indirection level, it looks like a pointer - are wrong.
I'm sorry, I don't know which popular idioms you are referring to, do you have any links to them? wikipedia? Maybe that helps to understand what you have in mind. The only thing that I wanted to point out is, that cbegin/cend is not a requirement for every written view.
I'm not talking you are wrong and thanks for clarifying. I'm simply want to get a confirmation that is not a library design or implementation bug before to start adapting my code.
Ah okay, it is expected that some ranges/views can't be const.