名稱空間
變體
操作

std::ranges::common_range

來自 cppreference.com
< cpp‎ | ranges
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
定義於標頭檔案 <ranges>
template< class T >

concept common_range =

    ranges::range<T> && std::same_as<ranges::iterator_t<T>, ranges::sentinel_t<T>>;
(C++20 起)

common_range 概念是 range 的一個細化,其 std::ranges::begin()std::ranges::end() 返回相同的型別(例如,所有標準庫容器)。

[編輯] 示例

#include <ranges>
 
struct A
{
    char* begin();
    char* end();
};
static_assert( std::ranges::common_range<A> );
 
struct B
{
    char* begin();
    bool end();
};  // not a common_range: begin/end have different types
static_assert( not std::ranges::common_range<B> );
 
struct C
{
    char* begin();
};  // not a common_range, not even a range: has no end()
static_assert( not std::ranges::common_range<C> );
 
int main() {}

[編輯] 參閱

view 轉換為 common_range
(類模板) (範圍介面卡物件)[編輯]