std::ranges::sized_range, std::ranges::disable_sized_range

< cpp‎ | ranges
Ranges library
Range access
Range conversions

Range primitives

Dangling iterator handling
Range concepts

Range factories
Range adaptors
Range generators
Range adaptor objects
Range adaptor closure objects
Helper items
(until C++23)(C++23)

Defined in header <ranges>
template< class T >

concept sized_range = ranges::range<T> &&
    requires(T& t) {

(1) (since C++20)
template< class >
inline constexpr bool disable_sized_range = false;
(2) (since C++20)
1) The sized_range concept specifies the requirements of a range type that knows its size in constant time with the size function.
2) disable_sized_range exists to allow use of range types that provide a size function (either as a member or as a non-member) but do not in fact model sized_range. Users may specialize disable_sized_range for cv-unqualified program-defined types. Such specializations shall be usable in constant expressions and have type const bool.


[edit] Semantic requirements

1) Given an lvalue t of type std::remove_reference_t<T>, T models sized_range only if

[edit] Notes

disable_sized_range cannot be used to opt-out a range whose iterator and sentinel satisfy sized_sentinel_for; std::disable_sized_sentinel_for must be used instead.

disable_sized_range cannot be specialized for array types or reference types.

[edit] Example

#include <forward_list>
#include <list>
#include <ranges>
    std::ranges::sized_range<std::list<int>> and
    not std::ranges::sized_range<std::forward_list<int>>
int main() {}

[edit] See also

specifies a range whose iterator type satisfies random_access_iterator
(concept) [edit]
specifies a range whose iterator type satisfies contiguous_iterator
(concept) [edit]