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

Header: <ranges>

  1. The sized_range concept specifies the requirements of a range type that knows its size in constant time with the size function.

# Declarations

template< class T >
concept sized_range = ranges::range<T> &&
requires(T& t) {
ranges::size(t);
};

(since C++20)

template< class >
constexpr bool disable_sized_range = false;

(since C++20)

# 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.

# Example

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

# See also