We use C++ and this is why we can't have nice things. It's 2024, we still can't split a string w/o jumping through hoops. Just look at this: https://cplusplus.github.io/LWG/issue4017. One option is to use std::views::drop in a hacky way to fix this. But then we run into the fact that std::views::split isn't even implemented in AppleClang 14...
So here is our own implementation. More user-friendly, and more efficient.
template<class Container >
requires std::is_same_v<std::remove_cv_t<typename Container::value_type::value_type>, char> && (!
is_initializer_list_v<Container>)
| detail::SplitView::operator Container |
( |
| ) |
const |
|
inline |
Converts this view to a container of string-like elements.
This operator enables implicit conversion to various container types (e.g., std::vector<std::string>, std::set<std::string_view>) for convenient use in initialization and assignment contexts.
The initializer_list exclusion in the requires clause is necessary to prevent ambiguous overload resolution when assigning to containers. Without it, v = split(...) would be ambiguous because std::vector::operator= has overloads for both const vector& and initializer_list<value_type>. Since initializer_list<string_view> technically satisfies the Container::value_type::value_type == char constraint, the compiler would consider both conversion paths and fail with an ambiguity error.
- Template Parameters
-
| Container | Target container type. Must hold string-like elements. |
- Returns
- Container populated with the string chunks from this view.