命名空间
变体
操作

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

来自 cppreference.cn
 
 
范围库
范围适配器
 
 
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

[编辑] 参见

返回一个等于范围大小的整数
(定制点对象)[编辑]
返回一个等于范围大小的有符号整数
(定制点对象)[编辑]