std::ranges::lazy_split_view
的推导指南
来自 cppreference.com
< cpp | ranges | lazy split view
template< class R, class P > lazy_split_view( R&&, P&& ) |
(1) | (自 C++20) |
template< ranges::input_range R > lazy_split_view( R&&, ranges::range_value_t<R> ) |
(2) | (自 C++20) |
这些 推导指南 是为了 lazy_split_view 提供的,允许从范围和分隔符中推导。
1) 分隔符是元素的范围。
2) 分隔符是单个元素。
[编辑] 示例
运行此代码
#include <ranges> #include <string_view> #include <type_traits> using std::operator""sv; int main() { std::ranges::lazy_split_view w1{"a::b::c"sv, "::"sv}; // type of w1 is lazy_split_view<string_view, string_view>: static_assert(std::is_same_v< decltype(w1), std::ranges::lazy_split_view< std::basic_string_view<char, std::char_traits<char>>, std::basic_string_view<char, std::char_traits<char>>>>); std::ranges::lazy_split_view w2{"x,y,z"sv, ','}; // type of w2 is lazy_split_view<string_view, single_view<char>>: static_assert(std::is_same_v< decltype(w2), std::ranges::lazy_split_view< std::basic_string_view<char, std::char_traits<char>>, std::ranges::single_view<char>>>); }