class template
<functional>
std::modulustemplate <class T> struct modulus;
Modulus function object class
Binary function object class whose call returns the result of the modulus operation between its two arguments (as returned by operator %).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 modulus : binary_function <T,T,T> {
T operator() (const T& x, const T& y) const {return x%y;}
};
1
2
3
4
5
6
template <class T> struct modulus {
T operator() (const T& x, const T& y) const {return x%y;}
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
};
operator()
second_argument_type T Type of the second argument in member operator()
result_type T Type returned by member operator()
x%y
).
1
2
3
4
5
6
7
8
9
10
11
12
13
// modulus example
#include <iostream> // std::cout
#include <functional> // std::modulus, std::bind2nd
#include <algorithm> // std::transform
int main () {
int numbers[]={1,2,3,4,5};
int remainders[5];
std::transform (numbers, numbers+5, remainders, std::bind2nd(std::modulus<int>(),2));
for (int i=0; i<5; i++)
std::cout << numbers[i] << " is " << (remainders[i]==0?"even":"odd") << '\n';
return 0;
}
1 is odd 2 is even 3 is odd 4 is even 5 is odd
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