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

78 lines
3.3 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.prim.size]
# 25 Ranges library [[ranges]](./#ranges)
## 25.3 Range access [[range.access]](range.access#range.prim.size)
### 25.3.10 ranges::size [range.prim.size]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1024)
The name ranges::size denotes a customization point
object ([[customization.point.object]](customization.point.object "16.3.3.3.5Customization Point Object types"))[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1028)
Given a subexpression E with type T,
let t be an lvalue that denotes the reified object for E[.](#2.sentence-1)
Then:
- [(2.1)](#2.1)
If T is an array of unknown bound ([[dcl.array]](dcl.array#term.array.type "9.3.4.5Arrays")), ranges::size(E) is ill-formed[.](#2.1.sentence-1)
- [(2.2)](#2.2)
Otherwise, if T is an array type, ranges::size(E) is expression-equivalent to auto(extent_v<T>)[.](#2.2.sentence-1)
- [(2.3)](#2.3)
Otherwise, if disable_sized_range<remove_cv_t<T>> ([[range.sized]](range.sized "25.4.4Sized ranges"))
is false and auto(t.size()) is a valid expression of integer-like type ([[iterator.concept.winc]](iterator.concept.winc "24.3.4.4Concept weakly_­incrementable")), ranges::size(E) is expression-equivalent to auto(t.size())[.](#2.3.sentence-1)
- [(2.4)](#2.4)
Otherwise, if T is a class or enumeration type, disable_sized_range<remove_cv_t<T>> is false and auto(size(t)) is a valid expression of integer-like type
where the meaning of size is established as-if by performing
argument-dependent lookup only ([[basic.lookup.argdep]](basic.lookup.argdep "6.5.4Argument-dependent name lookup")),
then ranges::size(E) is expression-equivalent to
that expression[.](#2.4.sentence-1)
- [(2.5)](#2.5)
Otherwise, if *to-unsigned-like*(ranges::end(t) - ranges::begin(t)) ([[ranges.syn]](ranges.syn "25.2Header <ranges> synopsis"))
is a valid expression and
the types I and S of ranges::begin(t) and ranges::end(t) (respectively) model both [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<S, I> ([[iterator.concept.sizedsentinel]](iterator.concept.sizedsentinel "24.3.4.8Concept sized_­sentinel_­for")) and [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I>,
then ranges::size(E) is expression-equivalent to *to-unsigned-like*(ranges::end(t) - ranges::begin(t))[.](#2.5.sentence-1)
- [(2.6)](#2.6)
Otherwise, ranges::size(E) is ill-formed[.](#2.6.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1075)
[*Note [1](#note-1)*:
Diagnosable ill-formed cases above
result in substitution failure when ranges::size(E) appears in the immediate context of a template instantiation[.](#3.sentence-1)
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1082)
[*Note [2](#note-2)*:
Whenever ranges::size(E) is a valid expression, its
type is integer-like[.](#4.sentence-1)
— *end note*]