std::ranges:: contiguous_range
|
||||||||||||||||||||||
| Range primitives | |||||||
|
|||||||
| Range concepts | ||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||
| Range factories | |||||||||
|
|||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||
| Helper items | |||||||||||||||||
|
|
||||||||||||||||
|
ヘッダーで定義
<ranges>
|
||
|
template
<
class
T
>
concept contiguous_range
=
|
(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 <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がranges::contiguous_rangeであることは、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>>> ); }
関連項目
|
(C++20)
|
範囲が定数時間でそのサイズを知ることを指定する
(コンセプト) |
|
(C++20)
|
イテレータ型が
random_access_iterator
を満たす範囲を指定する
(コンセプト) |