In p0896r4
23.7.11.1 Overview [range.split.overview]
- split_view takes a View and a delimiter, and splits the View into subranges on the delimiter. The delimiter can be a single element or a View of elements.
Example (with slight modification to compile)
#include <iostream>
#include <ranges>
#include <string>
int main()
{
std::string str{"the quick brown fox"};
std::ranges::split_view sentence{str, ' '};
for (auto word : sentence) {
for (char ch : word)
std::cout << ch;
std::cout << "*";
}
return 0;
}
Outputs:
the*quick*brown*fox*
However this is printing char by char, why can't I print a word instead?
for (auto word : sentence)
std::cout << word << std::endl;
Error: https://godbolt.org/z/GsPrhz
<source>:10:19: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'std::ranges::split_view<std::ranges::ref_view<std::__cxx11::basic_string<char> >, std::ranges::single_view<char> >::_OuterIter<true>::value_type')
Question: can I print the words? or does std::ranges::single_view<char> pose a contraint ?