24 Ranges library [ranges]

24.3 Range access [range.access]

24.3.10 ranges​::​size [range.prim.size]

The name ranges​::​size denotes a customization point object ([customization.point.object]).
Given a subexpression E with type T, let t be an lvalue that denotes the reified object for E.
Then:
  • If T is an array of unknown bound ([dcl.array]), ranges​::​size(E) is ill-formed.
  • Otherwise, if T is an array type, ranges​::​size(E) is expression-equivalent to decay-copy(extent_­v<T>).
  • Otherwise, if disable_­sized_­range<remove_­cv_­t<T>> ([range.sized]) is false and decay-copy(t.size()) is a valid expression of integer-like type ([iterator.concept.winc]), ranges​::​size(E) is expression-equivalent to decay-copy(t.size()).
  • Otherwise, if T is a class or enumeration type, disable_­sized_­range<remove_­cv_­t<T>> is false and decay-copy(size(t)) is a valid expression of integer-like type with overload resolution performed in a context in which unqualified lookup for size finds only the declarations void size(auto&) = delete; void size(const auto&) = delete; then ranges​::​size(E) is expression-equivalent to decay-copy(size(t)) with overload resolution performed in the above context.
  • 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<I>, then ranges​::​size(E) is expression-equivalent to to-unsigned-like(ranges​::​end(t) - ranges​::​begin(t)).
  • Otherwise, ranges​::​size(E) is ill-formed.
[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]
[Note 2:
Whenever ranges​::​size(E) is a valid expression, its type is integer-like.
— end note]