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