std::ranges::transform_view<V,F>::size
来自 cppreference.cn
< 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) |
返回等于范围大小的有符号整数 (定制点对象) |