命名空间
变体
操作

std::plus

来自 cppreference.cn
 
 
 
函数对象
函数调用
(C++17)(C++23)
恒等函数对象
(C++20)
透明运算符包装器
(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)

旧绑定器和适配器
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)  
(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
(直到 C++17*)(直到 C++17*)
(直到 C++17*)(直到 C++17*)

(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
 
定义于头文件 <functional>
template< class T >
struct plus;
(直到 C++14)
template< class T = void >
struct plus;
(C++14 起)

用于执行加法的功能对象。实际上对类型 T 的两个实例调用 operator+

目录

[编辑] 特化

当未指定 T 时,标准库提供了 std::plus 的特化,它允许推导参数类型和返回类型。

函数对象,实现 x + y 并推导参数和返回类型
(类模板特化) [编辑]
(C++14 起)

[编辑] 成员类型

类型 定义
result_type (C++17 中已弃用)(C++20 中已移除) T
first_argument_type (C++17 中已弃用)(C++20 中已移除) T
second_argument_type (C++17 中已弃用)(C++20 中已移除) T

这些成员类型通过公有继承 std::binary_function<T, T, T> 获得。

(C++11 前)

[编辑] 成员函数

operator()
返回两个参数的和
(公有成员函数) [编辑]

std::plus::operator()

T operator()( const T& lhs, const T& rhs ) const;
(C++14 起为 constexpr)

返回 lhsrhs 的和。

参数

lhs, rhs - 要求和的值

返回值

lhs + rhs 的结果。

[编辑] 异常

可能抛出实现定义的异常。

可能的实现

constexpr T operator()(const T& lhs, const T& rhs) const 
{
    return lhs + rhs;
}