Consider the following code:
#include <ranges>
int main() {
constexpr int a[] = {1, 2, 3, 4};
constexpr auto r = a | std::views::take(3);
static_assert(*r.begin() == 1);
}
msvc accept it, gcc rejects it with:
<source>:5:44: error: 'std::ranges::take_view<std::ranges::ref_view<const int [4]> >{3, std::ranges::ref_view<const int [4]>{(& a)}}' is not a constant expression
5 | constexpr auto r = a | std::views::take(3);
| ^
Why does r
is not a constant expression?