ranges v3 any_view & constant

439 Views Asked by At

The following trivial code is failing:

#include <vector>
#include <range/v3/all.hpp>

int main()
{
    std::vector<int> const v{ 1, 2, 3, 4 };
    ranges::any_view<int, ranges::category::bidirectional |
                              ranges::category::sized> const a{v};
    ranges::begin(a);
}

but if remove the constant here:

 a { v };

everything is OK. Is it a bug? Or do I not understand the semantics of any_view.

UPD: This is MSVC 16.9.0 Preview 1.0 compiler.

1

There are 1 best solutions below

2
On

ranges::begin(a) invokes

template<typename R>
ranges::_begin_::fn::operator ()(R && r)

that expects modifiable or r-value parameter r.

a declared as const a{v} would call ranges::_begin_::fn::operator ()<const ranges::any_view<...>>(const ranges::any_view<...> && r) that is not possible since it would bind r-value a to l-value parameter.