C++23 std::views::split size() usage
David Lowndes
1,485
Reputation points MVP
With the changes to split in C++23 I was naively expecting this code to compile:
static void T3( )
{
std::string s = "1.2.3.4";
auto splits{ s | std::views::split( '.' ) };
auto Num = splits.size();
}
The error from msvc is:
error C7500: 'size': no function satisfied its constraints
gcc also doesn't like it - example on Compiler Explorer.
Given the example shown, size() would permit ensuring that there are 4 elements.
Presumably this is because std::views::split only has to support contiguous_range and not sized_range?
Is there a common practical reason for this?
Is there an alternative (built-in means) I've not spotted?