std::ranges...ge::subrange(3)
π std::ranges::subrange::subrange π
okay so bestie, welcome to the C++ Standard Libary manual β and yes, the header really spells it Libary, iconic behavior. The header title is std::ranges...ge::subrange(3), and this whole page is about the constructors of std::ranges::subrange. Buckle up, weβre building subranges π.
πΈ NAME πΈ
std::ranges::subrange::subrange β std::ranges::subrange::subrange
β¨ Synopsis β¨
okay so hereβs the constructor buffet. The little numbers (1) through (5) are the manpageβs labels, and the (since C++20) notes are kept too:
subrange() requires std::default_initializable<I> = default; // (1) (since C++20)
constexpr subrange( /*convertible-to-non-slicing*/<I> auto i, S s ) // (2) (since C++20)
requires (!/*store-size*/);
constexpr subrange( /*convertible-to-non-slicing*/<I> auto i, S s,
/*make-unsigned-like-t*/<std::iter_difference_t<I>> n ) // (3) (since C++20)
requires (K == ranges::subrange_kind::sized);
template< /*different-from*/<subrange> R >
requires ranges::borrowed_range<R> &&
/*convertible-to-non-slicing*/<ranges::iterator_t<R>, I> &&
std::convertible_to<ranges::sentinel_t<R>, S>
constexpr subrange( R&& r ) // (4) (since C++20)
requires (!/*store-size*/ || ranges::sized_range<R>);
template< ranges::borrowed_range R>
requires /*convertible-to-non-slicing*/<ranges::iterator_t<R>, I> &&
std::convertible_to<ranges::sentinel_t<R>, S>
constexpr subrange( R&& r,
/*make-unsigned-like-t*/<std::iter_difference_t<I>> n ) // (5) (since C++20)
requires (K == ranges::subrange_kind::sized)
: subrange{ranges::begin(r), ranges::end(r), n}
{}
Constructs a subrange. π«Ά
So hereβs the tea: 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. No cap.
- Default constructor. Value-initializes the stored iterator and sentinel as if by default member initializers
= I()and= S(), respectively. If the size is stored, it is initialized with0as if by the default member initializer= 0. - Constructs a
subrangefrom an iterator-sentinel pair. Initializes the stored iterator and sentinel withstd::move(i)andsrespectively. The behavior is undefined if[i, s)is not a valid range. - Constructs a
subrangefrom an iterator-sentinel pair and a size hint. Initializes the stored iterator and sentinel withstd::move(i)andsrespectively. If the size is stored, it is initialized withn. The behavior is undefined if[i, s)is not a valid range, ornis not equal toranges::distance(i, s)explicitly converted to its type. - Constructs a
subrangefrom a range. Equivalent tosubrange(r, static_cast</*make-unsigned-like-t*/<std::iter_difference_t<I>>>(ranges::size(r)))if the size is stored. Otherwise, equivalent tosubrange(ranges::begin(r), ranges::end(r)). - Constructs a
subrangefrom a range and a size hint. The behavior is undefined ifnis not equal toranges::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 the 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 fromFromtoTois 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. Thatβs the whole warning, bestie β do not slice those pointers π«Ά.
π¦ Defect reports π¦
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. The manpage columns are DR, Applied to, Behavior as published, and Correct behavior:
- LWG 3470 β Applied to: C++20. Behavior as published:
convertible-to-non-slicingrejected some valid qualification conversions. Correct behavior: made accepted. - P2393R1 β Applied to: C++20. Behavior as published: implicit conversion to an integer-class type might be invalid. Correct behavior: made explicit.
π Example π
This section is incomplete.
Reason: no example.
π Category π
- Todo no example
okay thatβs the whole page, bestie! The footer says source/version http://cppreference.com and date 2024.06.10, with the page title std::ranges...ge::subrange(3). Stay glittery, and may your constructors always match their constraints πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms