std::unary_negate
来自cppreference.com
< cpp | utility | functional
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <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是一个包装函数对象,一元谓词其持有的返回的补.Original:
unary_negate is a wrapper function object returning the complement of the unary predicate it holds.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
一元谓词的类型必须定义一个成员的类型,
argument_type,也就是转换为谓词的参数类型。从std::ref获得一元函数对象,std::cref,std::negate,std::logical_not,std::mem_fn,std::function,std::hash,或从另一个呼叫std::not1这种类型的定义,函数对象来自过时的std::unary_function. Original:
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. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
unary_negate对象很容易构造辅助函数std::not1.Original:
unary_negate objects are easily constructed with helper function std::not1.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 会员类型
| 类型
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
argument_type
|
Predicate::argument_type |
result_type
|
bool |
[编辑] 成员函数
| (constructor) |
constructs a new unary_negate object with the supplied predicate (公共成员函数) |
| operator() |
返回的逻辑补码的呼叫的结果,所存储的谓词 Original: returns the logical complement of the result of a call to the stored predicate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) |
的std :: unary_negate ::Original:std::unary_negate::The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.unary_negate
Original:
std::unary_negate::
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
| explicit unary_negate( Predicate const& pred ); |
||
Constructs a unary_negate function object with the stored predicate pred.
Parameters
| pred | - | 谓词函数对象
Original: predicate function object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
的std :: unary_negate ::Original:std::unary_negate::The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.operator()
Original:
std::unary_negate::
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
| bool operator()( argument_type const& x ) const; |
||
Returns the logical complement of the result of calling pred(x).
Parameters
| x | - | 参数传递到谓词
Original: argument to pass through to predicate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
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); */ }
Output:
3
[编辑] 另请参阅
| 包装函数对象返回的补其所持有的二元谓词 Original: wrapper function object returning the complement of the binary predicate it holds The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) | |
| (C++11) |
包装任何类型的可调用对象与指定的函数调用签名 Original: wraps callable object of any type with specified function call signature The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |
| 构造自定义std::unary_negate对象 Original: constructs custom std::unary_negate object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |
| (过时了) |
创建适配器兼容功能的包装对象从一个指针到函数 Original: creates an adaptor-compatible function object wrapper from a pointer to function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) |
| (过时了) |
适配器兼容的一元函数的基类 Original: adaptor-compatible unary function base class The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |