(One of) the problem here is that ranges::view::split
returns a range of ranges, and you cannot construct a std::string_view
directly from a range.
You want something like this:
auto view = s
| ranges::views::split(' ')
| ranges::views::transform([](auto &&rng) {
return std::string_view(&*rng.begin(), ranges::distance(rng));
});
There might be a better/easier way to do this but:
&*rng.begin()
will give you the address of the first character of the chunk in the original string.
ranges::distance(rng)
will give you the number of characters in this chunk. Note that this is slower than ranges::size
but required here because we cannot retrieve the size of rng
in constant time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…