名稱空間
變體
操作

std::sized_sentinel_for, std::disable_sized_sentinel_for

來自 cppreference.com
 
 
迭代器庫
迭代器概念
sized_sentinel_for
(C++20)

迭代器原語
演算法概念與工具
間接可呼叫概念
常用演算法要求
(C++20)
(C++20)
(C++20)
工具
(C++20)
迭代器介面卡
範圍訪問
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
定義於標頭檔案 <iterator>
template< class S, class I >

    concept sized_sentinel_for =
        std::sentinel_for<S, I> &&
        !std::disable_sized_sentinel_for<std::remove_cv_t<S>,
                                         std::remove_cv_t<I>> &&
        requires(const I& i, const S& s) {
            { s - i } -> std::same_as<std::iter_difference_t<I>>;
            { i - s } -> std::same_as<std::iter_difference_t<I>>;

        };
(1) (C++20 起)
template< class S, class I >
    inline constexpr bool disable_sized_sentinel_for = false;
(2) (C++20 起)
1) sized_sentinel_for 概念指定了迭代器型別 I 的物件和哨兵型別 S 的物件可以相減,以常數時間計算它們之間的距離。
2) disable_sized_sentinel_for 變數模板可用於防止可以相減但實際上不符合 sized_sentinel_for 模型的迭代器和哨兵滿足該概念。
程式可以為 cv 非限定的非陣列物件型別 SI 特化 disable_sized_sentinel_for,只要其中至少有一個是程式定義的型別。此類特化可在常量表達式中使用,並且型別為 const bool

目錄

[編輯] 語義要求

i 為型別 I 的迭代器,s 為型別 S 的哨兵,使得 [is) 表示一個範圍。令 n 為使 bool(i == s)true 所必需的 ++i 的最小應用次數。僅當所有以下條件都滿足時,IS 才符合 sized_sentinel_for<S, I> 模型:

[編輯] 相等性保持

標準庫概念的 requires 表示式中宣告的表示式要求是相等性保持的(除非另有說明)。

[編輯] 隱式表示式變體

一個使用了對某些常量左值運算元而言非修改表示式的 requires 表示式,也需要隱式表示式變體

[編輯] 參閱

指定範圍在常數時間內知道其大小
(概念) [編輯]
返回等於範圍大小的整數
(自定義點物件)[編輯]