std::unary_negate
来自cppreference.com
< cpp | utility | functional
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <functional> 中定义
|
||
template< class Predicate > struct unary_negate : public std::unary_function<Predicate::argument_type, bool>; |
(至 C++11) | |
template< class Predicate > struct unary_negate; |
(C++11 起) | |
unary_negate
是一个包装函数对象,一元谓词其持有的返回的补.原文:
unary_negate
is a wrapper function object returning the complement of the unary predicate it holds.一元谓词的类型必须定义一个成员的类型,
argument_type
,也就是转换为谓词的参数类型。从std::ref获得一元函数对象,std::cref,std::negate,std::logical_not,std::mem_fn,std::function,std::hash,或从另一个呼叫std::not1这种类型的定义,函数对象来自过时的std::unary_function. 原文:
The unary predicate type must define a member type,
argument_type
, that is convertible to the predicate's parameter type. The unary function objects obtained from std::ref, std::cref, std::negate, std::logical_not, std::mem_fn, std::function, std::hash, or from another call to std::not1 have this type defined, as are function objects derived from the deprecated std::unary_function. unary_negate
对象很容易构造辅助函数std::not1.原文:
unary_negate
objects are easily constructed with helper function std::not1.目录 |
[编辑] 会员类型
类型
|
Definition |
argument_type
|
Predicate::argument_type |
result_type
|
bool |
[编辑] 成员函数
(constructor) |
constructs a new unary_negate object with the supplied predicate (公共成员函数) |
operator() |
返回的逻辑补码的呼叫的结果,所存储的谓词 原文: returns the logical complement of the result of a call to the stored predicate (公共成员函数) |
的std :: unary_negate ::unary_negate
explicit unary_negate( Predicate const& pred ); |
||
Constructs a unary_negate
function object with the stored predicate pred
.
Parameters
pred | - | 谓词函数对象
|
的std :: unary_negate ::operator()
bool operator()( argument_type const& x ) const; |
||
Returns the logical complement of the result of calling pred(x).
Parameters
x | - | 参数传递到谓词
原文: argument to pass through to predicate |
Return value
The logical complement of the result of calling pred(x).
[编辑] 示例
#include <algorithm> #include <functional> #include <iostream> #include <vector> struct less_than_7 : std::unary_function<int, bool> { bool operator()(int i) const { return i < 7; } }; int main() { std::vector<int> v; for (int i = 0; i < 10; ++i) v.push_back(i); std::unary_negate<less_than_7> not_less_than_7((less_than_7())); std::cout << std::count_if(v.begin(), v.end(), not_less_than_7); /* C++11 solution: // Use std::function<bool (int)> std::function<bool (int)> not_less_than_7 = [](int x)->bool{ return !less_than_7()(x); }; std::cout << std::count_if(v.begin(), v.end(), not_less_than_7); */ }
输出:
3
[编辑] 另请参阅
包装函数对象返回的补其所持有的二元谓词 原文: wrapper function object returning the complement of the binary predicate it holds (类模板) | |
(C++11) |
包装任何类型的可调用对象与指定的函数调用签名 原文: wraps callable object of any type with specified function call signature (类模板) |
构造自定义std::unary_negate对象 原文: constructs custom std::unary_negate object (函数模板) | |
(已弃用) |
创建适配器兼容功能的包装对象从一个指针到函数 原文: creates an adaptor-compatible function object wrapper from a pointer to function (函数模板) |
(已弃用) |
适配器兼容的一元函数的基类 原文: adaptor-compatible unary function base class (类模板) |