The
subrange
class template combines together an iterator and a sentinel into a single
view
. It models
sized_range
whenever the final template parameter is
subrange_kindâ::âsized(which happens when
std::sized_sentinel_for<S, I>is satisfied or when size is passed explicitly as a constructor argument).
3)Determines whether
From
is convertible to
To
without derived-to-base conversion:
[edit] Data members Member Definition constexpr boolStoreSize
[static] K == ranges::subrange_kind::sized &&
!std::sized_sentinel_for<S, I>
I
begin_
an iterator to the beginning of the subrange
S
end_
a sentinel denoting the end of the subrange
make-unsigned-like-t
<std::iter_difference_t<I>> size_
StoreSize
is true) the size of the subrange
subrange
subrange
to a pair-like type
subrange
is empty
subrange
subrange
with its iterator decremented by a given distance
subrange
with its iterator advanced by a given distance
std::ranges::view_interface<D>
) [edit] returns a sentinel for the constant iterator of the range
std::ranges::view_interface<D>
) [edit] returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
std::ranges::view_interface<D>
) [edit] gets the address of derived view's data, provided only if its iterator type satisfies contiguous_iterator
std::ranges::view_interface<D>
) [edit] returns the first element in the derived view, provided if it satisfies forward_range
std::ranges::view_interface<D>
) [edit] returns the last element in the derived view, provided only if it satisfies bidirectional_range
and common_range
std::ranges::view_interface<D>
) [edit] returns the n
th element in the derived view, provided only if it satisfies random_access_range
std::ranges::view_interface<D>
) [edit] [edit] Deduction guides [edit] Non-member functions [edit] Helper types [edit] Helper templates
This specialization of ranges::enable_borrowed_range makes subrange
satisfy borrowed_range
.
#include <map> #include <print> #include <ranges> void make_uppercase(char& v) { v += 'A' - 'a'; } void uppercase_transform(std::multimap<int, char>& m, int k) { auto [first, last] = m.equal_range(k); for (auto& [_, v] : std::ranges::subrange(first, last)) make_uppercase(v); } int main() { std::multimap<int, char> mm{{4, 'a'}, {3, '-'}, {4, 'b'}, {5, '-'}, {4, 'c'}}; std::println("Before: {}", mm); uppercase_transform(mm, 4); std::println("After: {}", mm); }
Output:
Before: {3: '-', 4: 'a', 4: 'b', 4: 'c', 5: '-'} After: {3: '-', 4: 'A', 4: 'B', 4: 'C', 5: '-'}[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 3470 C++20convertible-to-non-slicing
might reject qualification conversions always accepts them [edit] See also [edit] External links
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4