std::plus<void>
来自cppreference.com
< cpp | utility | functional
工具库
函数对象
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
旧绑定器与适配器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
在标头
<functional>
定义
|
||
template<>
class plus<void>; |
(C++14 起) | |
std::plus<> 是推导参数和返回类型的 std::plus 特化。
成员类型
成员类型 | 定义 |
is_transparent
|
/* 未指定 */ |
成员函数
operator()
|
返回二个参数的和 (公开成员函数) |
std::plus<>::operator()
template< class T, class U>
constexpr auto
operator()( T&& lhs,
U&& rhs )
const |
||
返回 lhs
与 rhs
的和。
参数
lhs, rhs | - | 要求和的值 |
返回值
lhs + rhs 的结果。
注意
成员类型 is_transparent
指示调用方,此函数对象是一个通透函数对象:它接受任意类型的参数并使用完美转发,这在将函数对象在多种语境中,或以右值参数使用时,避免不需要的复制和转换。特别是,诸如 std::set::find 和 std::set::lower_bound 的模板函数在其
Compare
类型上使用此类型。
示例
运行此代码
#include <functional> #include <iostream> int main() { std::string a = "Hello "; const char* b = "world"; std::cout << std::plus<>{}(a, b) << '\n'; }
输出:
Hello world