class template
<functional>
std::negatetemplate <class T> struct negate;
Negative function object class
Unary function object class whose call returns the result of negating its argument (as returned by the unary operator -).Negating a value returns the same value with the opposite sign.
Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a function call.
It is defined with the same behavior as:
1
2
3
template <class T> struct negate : unary_function <T,T> {
T operator() (const T& x) const {return -x;}
};
1
2
3
4
5
template <class T> struct negate {
T operator() (const T& x) const {return -x;}
typedef T argument_type;
typedef T result_type;
};
operator()
result_type bool Type returned by member operator()
-x
).
1
2
3
4
5
6
7
8
9
10
11
12
13
// negate example
#include <iostream> // std::cout
#include <functional> // std::negate
#include <algorithm> // std::transform
int main () {
int numbers[]={10,-20,30,-40,50};
std::transform (numbers, numbers+5, numbers, std::negate<int>());
for (int i=0; i<5; i++)
std::cout << numbers[i] << ' ';
std::cout << '\n';
return 0;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4