Difference between revisions of "cpp/utility/functional/plus"
From cppreference.com
< cpp | utility | functional
m (Update links.) |
(Start describing C++14 function objects) |
||
Line 3: | Line 3: | ||
{{dcl begin}} | {{dcl begin}} | ||
{{dcl header | functional }} | {{dcl header | functional }} | ||
− | {{dcl | | + | {{dcl rev begin}} |
+ | {{dcl | until=c++14 | | ||
template< class T > | template< class T > | ||
struct plus; | struct plus; | ||
}} | }} | ||
+ | {{dcl | since=c++14 | | ||
+ | template< class T {{=}} void > | ||
+ | struct plus; | ||
+ | }} | ||
+ | {{dcl rev end}} | ||
{{dcl end}} | {{dcl end}} | ||
Function object for performing addition. Effectively calls {{c|operator+}} on two instances of type {{tt|T}}. | Function object for performing addition. Effectively calls {{c|operator+}} on two instances of type {{tt|T}}. | ||
+ | |||
+ | ===Specializations=== | ||
+ | The standard library provides a specialization of {{tt|std::plus}} when {{tt|T}} is not specified, which leaves the parameter types and return type to be deduced. | ||
+ | {{dsc begin}} | ||
+ | {{dsc inc | cpp/utility/functional/dsc plus_void}} {{mark c++14}} | ||
+ | {{dsc end}} | ||
===Member types=== | ===Member types=== |
Revision as of 11:51, 6 August 2013
Defined in header <functional>
|
||
template< class T > struct plus; |
(until C++14) | |
template< class T = void > struct plus; |
(since C++14) | |
Function object for performing addition. Effectively calls operator+ on two instances of type T
.
Contents |
Specializations
The standard library provides a specialization of std::plus
when T
is not specified, which leaves the parameter types and return type to be deduced.
(C++14) |
function object implementing x + y deducing parameter and return types (class template specialization) |
Member types
Type | Definition |
result_type
|
T
|
first_argument_type
|
T
|
second_argument_type
|
T
|
Member functions
operator() |
returns the sum of two arguments (public member function) |
std::plus::operator()
T operator()( const T& lhs, const T& rhs ) const; |
||
Returns the sum of lhs
and rhs
.
Parameters
lhs, rhs | - | values to sum |
Return value
The result of lhs + rhs.
Exceptions
(none)
Possible implementation
T operator()(const T &lhs, const T &rhs) const { return lhs + rhs; } |