modulus
描述 (Description)
它是一个模数函数对象类和二进制函数对象类,其调用返回其两个参数之间的模运算结果(由运算符%返回)。
声明 (Declaration)
以下是std :: modulus的声明。
template <class T> struct modulus;
C++11
template <class T> struct modulus;
参数 (Parameters)
T - 它是函数调用的参数和返回类型的一种类型。
返回值 (Return Value)
没有
异常 (Exceptions)
noexcep - 它不会抛出任何异常。
例子 (Example)
在下面的例子中解释了std :: modulus。
#include <iostream>
#include <functional>
#include <algorithm>
int main () {
int numbers[]={1,20,1003,42,56};
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
20 is even
1003 is odd
42 is even
56 is even