std::unary_function
来自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 <typename ArgumentType, typename ResultType> struct unary_function; |
(过时了) | |
unary_function是创建一个参数的函数对象的基类.Original:
unary_function is a base class for creating function objects with one argument.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_function不定义operator();预期派生类定义此。 unary_function只有两种类型 - argument_type和result_type - 模板参数的定义.Original:
unary_function does not define operator(); it is expected that derived classes will define this. unary_function provides only two types - argument_type and result_type - defined by the template parameters.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.
一些标准库函数对象适配器,如std::not1,要求他们适应有一定的定义的类型的函数对象;std::not1需要的函数对象,适应了一种名为
argument_type。从unary_function接受一个参数的函数对象,推导是一个简单的方法,使他们与这些适配器兼容.Original:
Some standard library function object adaptors, such as std::not1, require the function objects they adapt to have certain types defined; std::not1 requires the function object being adapted to have a type named
argument_type. Deriving function objects that take one argument from unary_function is an easy way to make them compatible with those adaptors.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_function被废弃,在C + +11。它的功能已经过时std::function.Original:
unary_function is deprecated in C++11. Its functionality has been made obsolete by std::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.
[编辑] 会员类型
| 类型
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
|
ArgumentType
|
result_type
|
ResultType
|
[编辑] 为例
#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::cout << std::count_if(v.begin(), v.end(), std::not1(less_than_7())); /* C++11 solution: // Cast to std::function<bool (int)> somehow - even with a lambda std::cout << std::count_if(v.begin(), v.end(), std::not1(std::function<bool (int)>([](int i){ return i < 7; })) ); */ }
Output:
3
[编辑] 另请参阅
| (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. (类模板) |
| (过时了) |
创建适配器兼容功能的包装对象从一个指针到函数 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 wrapper for a pointer to unary 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 binary 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. (类模板) |