名稱空間
變體
操作

std::ranges::transform_view<V,F>::size

來自 cppreference.com
 
 
範圍庫 (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 起)

返回元素數量。等價於 ranges::size(base_)

目錄

[編輯] 返回值

元素數量。

[編輯] 註解

如果 V 不滿足 forward_range,則在呼叫 begin() 後,size() 可能沒有良好定義。

[編輯] 示例

#include <cassert>
#include <cctype>
#include <iostream>
#include <ranges>
#include <string>
 
int main()
{
    std::string s{"The length of this string is 42 characters"};
    auto to_upper{[](unsigned char c) -> char { return std::toupper(c); }};
    auto tv{std::ranges::transform_view{s, to_upper}};
    for (assert(tv.size() == 42); const auto c : tv)
        std::cout << c;
}

輸出

THE LENGTH OF THIS STRING IS 42 CHARACTERS

[編輯] 參閱

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