std::ranges...iguous_range(3)
π NAME π
okay bestie, welcome to the std::ranges::contiguous_range(3) page from the C++ Standard Library π
this one is niche but iconic, iykyk.
std::ranges::contiguous_range β yes queen, that's the name, and that's also literally the concept. No cap.
πΈ Synopsis πΈ
π Defined in header <ranges>
β±οΈ Since C++20, periodt.
template< class T >
concept contiguous_range =
ranges::random_access_range<T> &&
std::contiguous_iterator<ranges::iterator_t<T>> &&
requires(T& t) {
{ ranges::data(t) } ->
std::same_as<std::add_pointer_t<ranges::range_reference_t<T>>>;
};
so the contiguous_range concept is a refinement of range β the way that ranges::begin returns a model of contiguous_iterator, and the customization point ranges::data is usable. that's the whole vibe check π«
π« Semantic requirements π«
T models contiguous_range only if, given an expression e such that decltype((e)) is T&, this holds:
std::to_address(ranges::begin(e)) == ranges::data(e)
periodt, that's the requirement. no extra lore, no secret handshake π«Ά
β¨ Example β¨
// Run this code β bestie, run it, it's giving compile-time main character energy π
#include <array>
#include <deque>
#include <list>
#include <ranges>
#include <set>
#include <valarray>
#include <vector>
template<typename T> concept CR = std::ranges::contiguous_range<T>;
int main()
{
int a[4];
static_assert(
CR<std::vector<int>> and
not CR<std::vector<bool>> and
not CR<std::deque<int>> and
CR<std::valarray<int>> and
CR<decltype(a)> and
not CR<std::list<int>> and
not CR<std::set<int>> and
CR<std::array<std::list<int>,42>>
);
}
the static_assert ate that whole lineup, lowkey obsessed π
β¨
π¦ See also π¦
ranges::sized_range(C++20) (concept) β specifies that a range knows its size in constant time.ranges::random_access_range(C++20) (concept) β specifies a range whose iterator type satisfiesrandom_access_iterator.
source/version: http://cppreference.com Β· date: 2024.06.10 β bye bestie, go be contiguous and iconic πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms