Files
2025-10-25 03:02:53 +03:00

95 lines
3.9 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[range.subrange.ctor]
# 25 Ranges library [[ranges]](./#ranges)
## 25.5 Range utilities [[range.utility]](range.utility#range.subrange.ctor)
### 25.5.4 Sub-ranges [[range.subrange]](range.subrange#ctor)
#### 25.5.4.2 Constructors and conversions [range.subrange.ctor]
[🔗](#lib:subrange,constructor)
`constexpr subrange([convertible-to-non-slicing](range.subrange.general#concept:convertible-to-non-slicing "25.5.4.1General[range.subrange.general]")<I> auto i, S s) requires (!StoreSize);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L2020)
*Preconditions*: [i, s) is a valid range[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L2024)
*Effects*: Initializes *begin_* with std::move(i) and *end_* withs[.](#2.sentence-1)
[🔗](#lib:subrange,constructor_)
`constexpr subrange([convertible-to-non-slicing](range.subrange.general#concept:convertible-to-non-slicing "25.5.4.1General[range.subrange.general]")<I> auto i, S s,
make-unsigned-like-t<iter_difference_t<I>> n)
requires (K == subrange_kind::sized);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L2038)
*Preconditions*: [i, s) is a valid range, andn == *to-unsigned-like*(ranges::distance(i, s)) is true[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L2044)
*Effects*: Initializes *begin_* with std::move(i) and *end_* withs[.](#4.sentence-1)
If *StoreSize* is true, initializes *size_* withn[.](#4.sentence-2)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L2050)
[*Note [1](#note-1)*:
Accepting the length of the range and storing it to later return fromsize() enables subrange to model [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]") even
when it stores an iterator and sentinel that do not model[sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")[.](#5.sentence-1)
— *end note*]
[🔗](#lib:subrange,constructor__)
`template<[different-from](range.utility.helpers#concept:different-from "25.5.2Helper concepts[range.utility.helpers]")<subrange> R>
requires [borrowed_range](range.range#concept:borrowed_range "25.4.2Ranges[range.range]")<R> &&
[convertible-to-non-slicing](range.subrange.general#concept:convertible-to-non-slicing "25.5.4.1General[range.subrange.general]")<iterator_t<R>, I> &&
[convertible_to](concept.convertible#concept:convertible_to "18.4.4Concept convertible_­to[concept.convertible]")<sentinel_t<R>, S>
constexpr subrange(R&& r) requires (!StoreSize || [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]")<R>);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L2069)
*Effects*: Equivalent to:
- [(6.1)](#6.1)
If *StoreSize* is true,subrange(r, static_cast<decltype(*size_*)>(ranges::size(r)))[.](#6.1.sentence-1)
- [(6.2)](#6.2)
Otherwise, subrange(ranges::begin(r), ranges::end(r))[.](#6.2.sentence-1)
[🔗](#lib:operator_PairLike,subrange)
`template<[different-from](range.utility.helpers#concept:different-from "25.5.2Helper concepts[range.utility.helpers]")<subrange> PairLike>
requires [pair-like-convertible-from](range.subrange.general#concept:pair-like-convertible-from "25.5.4.1General[range.subrange.general]")<PairLike, const I&, const S&>
constexpr operator PairLike() const;
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L2087)
*Effects*: Equivalent to: return PairLike(*begin_*, *end_*);