Difference between revisions of "cpp/ranges/split view"
D41D8CD98F (Talk | contribs) (+ Call signature) |
D41D8CD98F (Talk | contribs) |
||
Line 18: | Line 18: | ||
{{dcl h|Call signature}} | {{dcl h|Call signature}} | ||
{{dcl|1= | {{dcl|1= | ||
− | template< | + | template< ranges::viewable_range R, class Pattern > |
requires /* see below */ | requires /* see below */ | ||
− | constexpr | + | constexpr ranges::view auto split( R&& r, Pattern&& pattern ); |
}} | }} | ||
{{dcl|1= | {{dcl|1= | ||
Line 36: | Line 36: | ||
{{tt|split_view}} models the concepts {{lconcept|forward_range}}, and {{lconcept|common_range}} when the underlying {{lconcept|view}} {{tt|V}} models respective concepts. | {{tt|split_view}} models the concepts {{lconcept|forward_range}}, and {{lconcept|common_range}} when the underlying {{lconcept|view}} {{tt|V}} models respective concepts. | ||
− | The inner range ({{c|ranges::range_reference_t<split_view>}}) is a {{c|ranges::subrange<ranges::iterator_t<V>>}}, which models | + | The inner range ({{c|ranges::range_reference_t<split_view>}}) is a {{c|ranges::subrange<ranges::iterator_t<V>>}}, which models {{lconcept|common_range}}, models {{lconcept|sized_range}} when {{c|ranges::iterator_t<V>}} models {{c|std::sized_sentinel_for<ranges::iterator_t<V>>}}, and models {{lconcept|contiguous_range}}, {{lconcept|random_access_range}}, {{lconcept|bidirectional_range}}, and {{lconcept|forward_range}} when {{tt|V}} models respective concepts. |
{{cpp/expr-eq}} | {{cpp/expr-eq}} |
Revision as of 13:29, 31 October 2021
Defined in header <ranges>
|
||
template< ranges::forward_range V, ranges::forward_range Pattern > requires ranges::view<V> && ranges::view<Pattern> && |
(1) | (since C++20) |
namespace views { inline constexpr /*unspecified*/ split = /*unspecified*/; |
(2) | (since C++20) |
Call signature |
||
template< ranges::viewable_range R, class Pattern > requires /* see below */ |
||
template< class Pattern > constexpr /*range adaptor closure*/ split( Pattern&& pattern ); |
||
split_view
models the concepts forward_range
, and common_range
when the underlying view
V
models respective concepts.
The inner range (ranges::range_reference_t<split_view>) is a ranges::subrange<ranges::iterator_t<V>>, which models common_range
, models sized_range
when ranges::iterator_t<V> models std::sized_sentinel_for<ranges::iterator_t<V>>, and models contiguous_range
, random_access_range
, bidirectional_range
, and forward_range
when V
models respective concepts.
Contents |
Expression-equivalent
Expression e is expression-equivalent to expression f, if
- e and f have the same effects, and
- either both are constant subexpressions or else neither is a constant subexpression, and
- either both are potentially-throwing or else neither is potentially-throwing (i.e. noexcept(e) == noexcept(f)).
Data members
Typical implementations of split_view
hold three non-static data members:
- the underlying
view
of typeV
(shown here asbase_
for exposition only), and - the pattern (shown here as
pattern_
for exposition only) that is used as a delimiter to split the underlyingview
. - an object equivalent to std::optional<ranges::subrange<ranges::iterator_t<V>>> (shown here as
cached_begin_
for exposition only) that caches the result of a first call tobegin()
.
Member functions
constructs a split_view (public member function) | |
returns a copy of the underlying (adapted) view (public member function) | |
returns an iterator to the beginning (public member function) | |
returns an iterator or a sentinel to the end (public member function) | |
(C++20) |
searches for the next occurrence of the pattern (exposition-only member function*) |
Inherited from std::ranges::view_interface | |
returns whether the derived view is empty. Provided if it satisfies sized_range or forward_range . (public member function of std::ranges::view_interface<D> )
| |
(C++23) |
returns a constant iterator to the beginning of the range. (public member function of std::ranges::view_interface<D> )
|
(C++23) |
returns a sentinel for the constant iterator of the range. (public member function of std::ranges::view_interface<D> )
|
returns whether the derived view is not empty. Provided if ranges::empty is applicable to it. (public member function of std::ranges::view_interface<D> )
| |
returns the first element in the derived view. Provided if it satisfies forward_range . (public member function of std::ranges::view_interface<D> )
|
Nested classes
(C++20) |
the iterator type (exposition-only member class*) |
(C++20) |
the sentinel type (exposition-only member class*) |
Deduction guides
Notes
Example
A link to check the example: wandbox
#include <iostream> #include <iomanip> #include <ranges> #include <string_view> int main() { constexpr std::string_view words{"Hello-_-C++-_-23-_-!"}; constexpr std::string_view delim{"-_-"}; for (const std::string_view word : std::views::split(words, delim)) { std::cout << std::quoted(word) << ' '; } }
Output:
"Hello" "C++" "23" "!"
See also
a view over the subranges obtained from splitting another view using a delimiter(class template) (range adaptor object) | |
(C++20) |
a view consisting of the sequence obtained from flattening a view of range s(class template) (range adaptor object) |