std::ranges::contiguous_range
| Definido en el encabezado <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>>>;
};
|
(desde C++20) | |
El concepto contiguous_range es un refinamiento de range para el cual ranges::begin devuelve un modelo de contiguous_iterator y el punto de personalización ranges::data es utilizable.
Requisitos semánticos
T
modela
contiguous_range
solo si dada una expresión
e
tal que
decltype
(
(
e
)
)
es
T
&
,
std::
to_address
(
ranges::
begin
(
e
)
)
==
ranges::
data
(
e
)
.
Ejemplo
#include <array> #include <deque> #include <list> #include <mdspan> #include <ranges> #include <set> #include <span> #include <string_view> #include <valarray> #include <vector> template<typename T> concept CR = std::ranges::contiguous_range<T>; // zstring siendo un ranges::contiguous_range no tiene que ser un ranges::sized_range struct zstring { struct sentinel { friend constexpr bool operator==(const char* str, sentinel) noexcept { return *str == '\0'; } }; const char* str; const char* begin() const noexcept { return str; } sentinel end() const noexcept { return {}; } }; 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>> and CR<std::string_view> and CR<zstring> and CR<std::span<const int>> and not CR<std::mdspan<int, std::dims<1>>> ); }
Véase también
|
(C++20)
|
especifica que un rango conoce su tamaño en tiempo constante
(concepto) |
|
(C++20)
|
especifica un rango cuyo tipo de iterador satisface
random_access_iterator
(concepto) |