std::ranges::transform_view<V,F>::size
来自cppreference.com
| |
(1) | (C++20 起) |
| |
(2) | (C++20 起) |
返回元素数。等价于 ranges::size(base_)。
返回值
元素数。
注解
若 V 不实现 forward_range,则 size() 在调用 begin() 后可能非良定义。
示例
运行此代码
#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) |
返回等于范围大小的有符号整数 (定制点对象) |