For the following code:
#include <iostream>
#include <string>
#include <ranges>
int main()
{
std::string s = " text ";
auto sv = std::ranges::views::split(s, ' ');
std::cout << std::ranges::distance(sv.begin(), sv.end());
}
the output is 2. The empty sub-range after the last delimiter is not present in the output range.
This seems inconsistent, since I expect there to be N+1
sub-ranges in the output range if there are N
occurrences of the delimiter in the input range. Why is this not the case?
Note that range-v3 does exactly the same thing, so I'm sure this is intentional, but I'd like to know why.