According to https://en.cppreference.com/w/cpp/ranges/split_view, std::ranges::split_view
must be available since C++20. However the example on the same page contains "C++23" in its text:
#include <iostream>
#include <iomanip>
#include <ranges>
#include <string_view>
int main() {
constexpr std::string_view words{"Hello-_-C++-_-23-_-!"};
constexpr std::string_view delim{"-_-"};
for (const std::string_view word : std::ranges::split_view(words, delim)) {
std::cout << std::quoted(word) << ' ';
}
}
Both GCC and MSVC refuse to accept this example in C++20 mode. MSVC in particular prints:
The contents of <ranges> are available only in c++latest mode with concepts support;
https://gcc.godbolt.org/z/4fGGb3aqY
GCC starts accepting the code with -std=c++2b
command-line switch (meaning forthcoming C++23), while MSVC even with /std:c++latest
option reports the error
error C2440: 'initializing': cannot convert from 'std::ranges::split_view<std::basic_string_view<char,std::char_traits<char>>,std::basic_string_view<char,std::char_traits<char>>>::_Outer_iter<true>::value_type' to 'std::basic_string_view<char,std::char_traits<char>>'
note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Demo: https://gcc.godbolt.org/z/6z48Mz45j
Is there something wrong with the example in C++20 mode, or it really requires some C++23 features from the compiler?