命名空间
变体
操作

std::plus<void>

来自 cppreference.cn
< cpp‎ | utility‎ | functional
 
 
 
函数对象
函数调用
(C++17)(C++23)
身份函数对象
(C++20)
透明运算符包装器
plus<>
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

旧式绑定器和适配器
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)  
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)

(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
 
定义于头文件 <functional>
template<>
class plus<void>;
(since C++14)

std::plus<void>std::plus 的特化,其中参数和返回类型被推导。

目录

[编辑] 成员类型

类型 定义
is_transparent 未指定

[编辑] 成员函数

operator()
返回两个参数的和
(public member function) [编辑]

std::plus<void>::operator()

template< class T, class U >

constexpr auto operator()( T&& lhs, U&& rhs ) const

    -> decltype(std::forward<T>(lhs) + std::forward<U>(rhs));

返回 lhsrhs 的和。

参数

lhs, rhs - 要相加的值

返回值

std::forward<T>(lhs) + std::forward<U>(rhs).

[编辑] 示例

#include <functional>
#include <iostream>
 
int main()
{
    auto string_plus = std::plus<void>{}; // “void” can be omitted
    std::string a = "Hello ";
    const char* b = "world";
    std::cout << string_plus(a, b) << '\n';
}

输出

Hello world