std::ranges::common_range(3)

πŸ“¦
version 2024.07.05 Β· 3 versions
, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

std::ranges::common_range β€” okay bestie, this is literally the std::ranges::common_range concept, and the manual page is std::ranges::common_range(3) from the C++ Standard Library. that’s the whole name vibe, periodt. πŸ’…


✨ Synopsis ✨

Defined in header <ranges>.

template< class T >

  concept common_range =
(since C++20)

    ranges::range<T> && std::same_as<ranges::iterator_t<T>,
          ranges::sentinel_t<T>>;

The common_range concept is a refinement of range for which std::ranges::begin() and std::ranges::end() return the same type (e.g. all standard library containers). no cap, that’s the whole point: begin and end are giving same-type energy. ✨


🌸 Example 🌸

run this code, bestie 🫢:

// Run this code

#include <ranges>

struct A {
    char* begin();
    char* end();
};
static_assert( std::ranges::common_range<A> );

struct B {
    char* begin();
    bool end();
};  // not a common_range: begin/end have different types
static_assert( not std::ranges::common_range<B> );

struct C {
    char* begin();
};  // not a common_range, not even a range: has no end()
static_assert( not std::ranges::common_range<C> );

int main() { }

πŸ‘€ See also πŸ‘€

  • ranges::common_view converts a view into a common_range
  • views::common β€” (class template) (range adaptor object) (C++20)

mwah πŸ’‹ source/version: cppreference.com Β· date: 2024.06.10 Β· page: std::ranges::common_range(3) β€” byeee, go be iconic with your ranges 🌈🫢

πŸ“¦ where this page comes from