名稱空間
變體
操作

std::ranges::view_interface<D>::size

來自 cppreference.com
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
 
constexpr auto size() requires ranges::forward_range<D> &&

    std::sized_sentinel_for<ranges::sentinel_t<D>,

                            ranges::iterator_t<D>>;
(1) (C++20 起)
constexpr auto size() const requires ranges::forward_range<const D> &&

    std::sized_sentinel_for<ranges::sentinel_t<const D>,

                            ranges::iterator_t<const D>>;
(2) (C++20 起)

size() 成員函式的預設實現透過計算哨兵與起始迭代器之間的差值來獲取範圍的大小。

目錄

[編輯] 返回值

1) to-unsigned-like (ranges::end(static_cast<D&>(this)) -
                     ranges::begin(static_cast<D&>(this)))
2) to-unsigned-like (ranges::end(static_cast<const D&>(this)) -
                     ranges::begin(static_cast<const D&>(this)))

[編輯] 注意

以下派生型別可以使用 size() 的預設實現

以下型別派生自 std::ranges::view_interface 且未宣告自己的 size() 成員函式,但它們不能使用預設實現,因為它們的迭代器和哨兵型別從不滿足 sized_sentinel_for

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 3646 C++20 size 函式的預設實現返回有符號型別 它們返回無符號型別

[編輯] 參閱

(C++17)(C++20)
返回容器或陣列的大小
(函式模板) [編輯]
返回等於範圍大小的整數
(定製點物件)[編輯]
返回等於範圍大小的有符號整數
(定製點物件)[編輯]