Namespaces
Variants

deduction guides for std::ranges::split_view

From cppreference.net
Ranges library
Range adaptors
template < class R, class P >

split_view ( R && , P && )

- > split_view < views:: all_t < R > , views:: all_t < P >> ;
(1) (C++20以降)
template < ranges:: input_range R >

split_view ( R && , ranges:: range_value_t < R > )

- > split_view < views:: all_t < R > , ranges:: single_view < ranges:: range_value_t < R >>> ;
(2) (C++20以降)

これらの deduction guides は、範囲とデリミタからの推論を可能にするために split_view に提供されています。

1) 区切り文字は要素の範囲です。
2) 区切り文字は単一の要素です。

#include <ranges>
#include <string_view>
#include <type_traits>
using std::operator""sv;
int main() {
    std::ranges::split_view w1{"a::b::c"sv, "::"sv};
    static_assert(std::is_same_v<
        decltype(w1),
        std::ranges::split_view<std::string_view, std::string_view>>);
    std::ranges::split_view w2{"x,y,z"sv, ','};
    static_assert(std::is_same_v<
        decltype(w2),
        std::ranges::split_view<std::string_view, std::ranges::single_view<char>>>);
}