std::ranges::contiguous_range
来自cppreference.com
| 在标头 <ranges> 定义
|
||
| template< class T > concept contiguous_range = |
(C++20 起) | |
contiguous_range 概念是 range 的精化,对于实现它的类型,ranges::begin 返回 contiguous_iterator 的实现,且定制点 ranges::data 可用。
语义要求
仅若给定表达式 e 使得 decltype((e)) 为 T&,std::to_address(ranges::begin(t)) == ranges::data(t) 时,T 实现 contiguous_range。
示例
运行此代码
#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>; // 作为 ranges::contiguous_range 的 zstring 不必是 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 (概念) |