std::ranges::contiguous_range
Определено в заголовке <ranges> | ||
|---|---|---|
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>>>;
};
| (с C++20) |
Концепция contiguous_range является уточнением концепции range, для которой ranges::begin возвращает модель contiguous_iterator, и точка настройки ranges::data может быть использована.
Семантические требования
T моделирует contiguous_range только если задано выражение e такое, что decltype((e)) является T&, std::to_address(ranges::begin(e)) == ranges::data(e).
Пример
#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>>
);
}См. также
|
(C++20) | определяет, что диапазон знает свой размер за постоянное время (концепция) |
|
(C++20) | определяет диапазон, тип итератора которого удовлетворяет random_access_iterator (концепция) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/contiguous_range