名稱空間
變體
操作

std::ranges::take_view<V>::size

來自 cppreference.com
< cpp‎ | ranges‎ | take_view
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
 
constexpr auto size() requires ranges::sized_range<V>;
(1) (C++20 起)
constexpr auto size() const requires ranges::sized_range<const V>;
(2) (C++20 起)

返回元素數量,其為傳遞給建構函式計數值與底層檢視大小兩者中的較小值。

base_ 為底層檢視,count_ 為底層計數器(若預設構造則等於 0)。等價於

auto n = ranges::size(base_);
return ranges::min(n, static_cast<decltype(n)>(count_));

目錄

[編輯] 引數

(無)

[編輯] 返回值

元素數量。

[編輯] 示例

#include <iostream>
#include <ranges>
 
int main()
{
    constexpr int arr[]{1, 2, 3};
 
    for (int i = 0; i != 6; ++i)
    {
        const auto tv = std::ranges::take_view{arr, i};
        std::cout << tv.size() << ' ';
    }
    std::cout << '\n';
}

輸出

0 1 2 3 3 3

[編輯] 參閱

返回等於範圍大小的整數
(定製點物件)[編輯]
返回等於範圍大小的有符號整數
(定製點物件)[編輯]