template <class T> struct logical_and; |
C++98 |
template <class T> struct logical_and : binary_function <T,T,bool> { bool operator() (const T& x, const T& y) const {return x&&y;} }; |
成员类型 | 定义 | 注释 |
first_argument_type | T | 成员operator()中第一个参数的类型 |
second_argument_type | T | 成员operator()中第二个参数的类型 |
result_type | bool | 成员operator()返回的类型 |
T operator() (const T& x, const T& y) |
// logical_and example #include <iostream> // std::cout, std::boolalpha #include <functional> // std::logical_and #include <algorithm> // std::transform int main () { bool foo[] = {true,false,true,false}; bool bar[] = {true,true,false,false}; bool result[4]; std::transform (foo, foo+4, bar, result, std::logical_and<bool>()); std::cout << std::boolalpha << "Logical AND:\n"; for (int i=0; i<4; i++) std::cout << foo[i] << " AND " << bar[i] << " = " << result[i] << "\n"; return 0; } |
logical_or | 逻辑或函数对象类(类模板) |
logical_not | 逻辑非函数对象类(类模板) |