std::ranges::contiguous_range
Von cppreference.com
| Definiert in der Header-Datei <ranges> |
||
| template< class T > concept contiguous_range = |
(seit C++20) | |
Das Konzept contiguous_range ist eine Verfeinerung von range, für die ranges::begin ein Modell von contiguous_iterator zurückgibt und der Customization Point ranges::data verwendbar ist.
[bearbeiten] Semantische Anforderungen
T modelliert contiguous_range nur, wenn für einen Ausdruck e, so dass decltype((e)) T& ist, gilt: std::to_address(ranges::begin(e)) == ranges::data(e).
[bearbeiten] Beispiel
Führen Sie diesen Code aus
#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 being a ranges::contiguous_range doesn't have to be a 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>>> ); }
[bearbeiten] Siehe auch
| (C++20) |
spezifiziert, dass ein Range seine Größe in konstanter Zeit kennt (Konzept) |
| (C++20) |
spezifiziert einen Range, dessen Iteratortyp random_access_iterator erfüllt(Konzept) |