std::ranges..._sized_range(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ NAME πŸŽ€

okay so bestie, this is the C++ Standard Library page for std::ranges::sized_range,std::ranges::disable_sized_range β€” yes, that exact comma-smooshed pair β€” aka std::ranges::sized_range and std::ranges::disable_sized_range. manual name folded in right here so you don't have to squint at a header line πŸ’…


✨ Synopsis ✨

Defined in header <ranges>
template< class T >

concept sized_range = ranges::range<T> &&
    requires(T& t) {                               (1) (since C++20)
        ranges::size(t);

    };
template< class >                                  (2) (since C++20)
inline constexpr bool disable_sized_range = false;
  1. so (1) is the sized_range concept: it specifies the requirements of a range type that knows its size in constant time with the size function. lowkey iconic.
  2. and (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. no cap.

🌸 Notes 🌸

  • real talk: 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.
  • also important, bestie: disable_sized_range cannot be specialized for array types or reference types. periodt.

πŸ¦‹ Example πŸ¦‹

run this code, it's giving very demure very mindful:

// Run this code

#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 πŸ’–

  • ranges::random_access_range β€” specifies a range whose iterator type satisfies random_access_iterator (concept) (C++20). iconic.
  • ranges::contiguous_range β€” specifies a range whose iterator type satisfies contiguous_iterator (concept) (C++20). slay.

and that's the whole page, bestie! source/version vibes: http://cppreference.com, dated 2024.06.10, page std::ranges..._sized_range(3). bye and go slay your ranges πŸ’œβœ¨

πŸ“¦ where this page comes from