std::ranges::transform_view<V,F>::size
來自 cppreference.com
< cpp | ranges | transform view
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
[編輯] 參閱
(C++20) |
返回等於範圍大小的整數 (定製點物件) |
(C++20) |
返回等於範圍大小的有符號整數 (定製點物件) |