I have read the latest draft where lazy_split_view
is added.
But later on, I realized that split_view
was renamed into lazy_split_view
, and the split_view
was renewed.
libstdc++
also recently implemented this by using GCC Trunk
version https://godbolt.org/z/9qG5T9n5h
I have a simple naive program here that shows the usage of two views, but I can't see their differences:
#include <iostream>
#include <ranges>
int main(){
std::string str { "one two three four" };
for (auto word : str | std::views::split(' ')) {
for (char ch : word)
std::cout << ch;
std::cout << '.';
}
std::cout << '\n';
for (auto word : str | std::views::lazy_split(' ')) {
for (char ch : word)
std::cout << ch;
std::cout << '.';
}
}
Output:
one.two.three..four.
one.two.three..four.
until I've noticed the differences when using as std::span<const char>
for both views.
In the first one: std::views::split
:
for (std::span<const char> word : str | std::views::split(' '))
the compiler accepts my code.
While in the second one: std::views::lazy_split
for (std::span<const char> word : str | std::views::lazy_split(' '))
throws compilation errors.
I know there will be differences between these two, but I can't easily spot them. Is this a defect report in C++20 or a new feature in C++23 (with changes), or both?