Files
cppdraft_translate/cppdraft/range/prim/size.md
2025-10-25 03:02:53 +03:00

3.3 KiB
Raw Blame History

[range.prim.size]

25 Ranges library [ranges]

25.3 Range access [range.access]

25.3.10 ranges::size [range.prim.size]

1

#

The name ranges::size denotes a customization point object ([customization.point.object]).

2

#

Given a subexpression E with type T, let t be an lvalue that denotes the reified object for E.

Then:

  • (2.1)

    If T is an array of unknown bound ([dcl.array]), ranges::size(E) is ill-formed.

  • (2.2)

    Otherwise, if T is an array type, ranges::size(E) is expression-equivalent to auto(extent_v).

  • (2.3)

    Otherwise, if disable_sized_range<remove_cv_t> ([range.sized]) is false and auto(t.size()) is a valid expression of integer-like type ([iterator.concept.winc]), ranges::size(E) is expression-equivalent to auto(t.size()).

  • (2.4)

    Otherwise, if T is a class or enumeration type, disable_sized_range<remove_cv_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]), then ranges::size(E) is expression-equivalent to that expression.

  • (2.5)

    Otherwise, if to-unsigned-like(ranges::end(t) - ranges::begin(t)) ([ranges.syn]) is a valid expression and the types I and S of ranges::begin(t) and ranges::end(t) (respectively) model both sized_sentinel_for<S, I> ([iterator.concept.sizedsentinel]) and forward_iterator, then ranges::size(E) is expression-equivalent to to-unsigned-like(ranges::end(t) - ranges::begin(t)).

  • (2.6)

    Otherwise, ranges::size(E) is ill-formed.

3

#

[Note 1:

Diagnosable ill-formed cases above result in substitution failure when ranges::size(E) appears in the immediate context of a template instantiation.

— end note]

4

#

[Note 2:

Whenever ranges::size(E) is a valid expression, its type is integer-like.

— end note]