C++23 std::views::split size() usage

David Lowndes 1,485 Reputation points MVP
2023-11-08T10:51:40.8533333+00:00

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?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,321 questions
{count} votes