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

2.1 KiB
Raw Blame History

[range.counted]

25 Ranges library [ranges]

25.7 Range adaptors [range.adaptors]

25.7.19 Counted view [range.counted]

1

#

A counted view presents a view of the elements of the counted range ([iterator.requirements.general]) i+[0, n) for an iterator i and non-negative integer n.

2

#

The name views::counted denotes a customization point object ([customization.point.object]).

Let E and F be expressions, let T be decay_t<decltype((E))>, and let D be iter_difference_t.

If decltype((F)) does not modelconvertible_to,views::counted(E, F) is ill-formed.

[Note 1:

This case can result in substitution failure when views::counted(E, F) appears in the immediate context of a template instantiation.

— end note]

Otherwise, views::counted(E, F) is expression-equivalent to:

  • (2.1)

    If T models contiguous_iterator, then span(to_address(E), static_cast<size_t>(static_cast(F))).

  • (2.2)

    Otherwise, if T models random_access_iterator, then subrange(E, E + static_cast(F)), except that E is evaluated only once.

  • (2.3)

    Otherwise,subrange(counted_iterator(E, F), default_sentinel).