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. |
| Заголовочный файл <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.
[править] Член типов
| Type
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 (public функция-член) |
| 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. (public функция-член) |
зЬй :: 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. |
зЬй :: 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); */ }
Вывод:
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. (шаблон класса) |