On this page
std::ranges::subrange<I,S,K>::subrange
|
(1) | (since C++20) |
|
(2) | (since C++20) |
|
(3) | (since C++20) |
|
(4) | (since C++20) |
|
(5) | (since C++20) |
Constructs a subrange
.
If K == ranges::subrange_kind::sized && !std::sized_sentinel_for<S, I>
, the size of the range is stored into the subrange
, as if stored by a member subobject of type /*make-unsigned-like-t*/<std::iter_difference_t<I>>
, where make-unsigned-like-t
is an exposition-only alias template that maps each integer-like type to its corresponding unsigned version. Otherwise, the size is not stored. The constant store-size
is true
if the size is stored, false
otherwise.
= I()
and = S()
, respectively. If the size is stored, it is initialized with 0
as if by the default member initializer = 0
.
subrange
from an iterator-sentinel pair. Initializes the stored iterator and sentinel with std::move(i)
and s
respectively. The behavior is undefined if [i, s)
is not a valid range.
subrange
from an iterator-sentinel pair and a size hint. Initializes the stored iterator and sentinel with std::move(i)
and s
respectively. If the size is stored, it is initialized with n
. The behavior is undefined if [i, s)
is not a valid range, or n
is not equal to ranges::distance(i, s)
explicitly converted to its type.
subrange
from a range. Equivalent to subrange(r, static_cast</*make-unsigned-like-t*/<std::iter_difference_t<I>>>(ranges::size(r)))
if the size is stored. Otherwise, equivalent to subrange(ranges::begin(r), ranges::end(r))
.
subrange
from a range and a size hint. The behavior is undefined if n
is not equal to ranges::distance(ranges::begin(r), ranges::end(r))
explicitly converted to its type.
The exposition only concept different-from
is modeled by types T
and U
if and only if std::decay_t<T>
and std::decay_t<U>
are different types.
The exposition only concept convertible-to-non-slicing
is satisfied or modeled by From
and To
if and only if std::convertible_to<From, To>
is satisfied or modeled respectively, and any of following conditions is satisfied:
- either
std::decay_t<From>
orstd::decay_t<To>
is not a pointer type, std::remove_pointer_t<From>(*)[]
is implicitly convertible tostd::remove_pointer_t<To>(*)[]
, i.e., the conversion fromFrom
toTo
is at most a qualification conversion.
Parameters
i | - | iterator that denotes the beginning of the range |
s | - | sentinel that denotes the end of the range |
r | - | range |
n | - | size hint, must be equal to the size of the range |
Notes
The exposition-only concept convertible-to-non-slicing
forbids the conversion from the pointer to derived class to the pointer to base class.
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++20 | convertible-to-non-slicing rejected some valid qualification conversions |
made accepted |
P2393R1 | C++20 | implicit conversion to an integer-class type might be invalid | made explicit |
Example
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/subrange/subrange