Namespaces
Variants

std::ranges:: approximately_sized_range

From cppreference.net
Ranges library
Range adaptors
Defined in header <ranges>
template < class T >

concept approximately_sized_range = ranges:: range < T > &&
requires ( T & t ) {
ranges :: reserve_hint ( t ) ;

} ;
(since C++26)

The approximately_sized_range concept specifies the requirements of a range type that can estimate its size in constant time with the reserve_hint function.

Contents

Semantic requirements

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

  • ranges :: reserve_hint ( t )
  • if ranges:: iterator_t < T > models forward_iterator , ranges :: reserve_hint ( t ) is well-defined regardless of the evaluation of ranges:: begin ( t ) (in other words, a single-pass approximately sized range may support a call to reserve_hint only before the first call to begin , but a forward range must support size at all times).

Notes

Feature-test macro Value Std Feature
__cpp_lib_ranges_reserve_hint 202502L (C++26) ranges::approximately_sized_range

Example

See also

specifies that a range knows its size in constant time
(concept)