std::is_bind_expression
来自cppreference.com
< cpp | utility | functional
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <functional> 中定义
|
||
template< class T > struct is_bind_expression; |
(C++11 起) | |
T
是std::bind的调用所产生的类型,这个模板提供成员value等于true。对于任何其他类型,value
是false.原文:
If
T
is the type produced by a call to std::bind, this template provides the member constant value equal true. For any other type, value
is false.这个模板可以专门为一个用户定义的类型,应被视为std::bind,如果它是一个绑定的子表达式的类型:当绑定生成的函数对象被调用时,这种类型的绑定参数的函数将被调用对象,将所有未绑定的参数传递给绑定生成的对象.....
原文:
This template may be specialized for a user-defined type which should be treated by std::bind as if it was the type of a bind subexpression: when a bind-generated function object is invoked, a bound argument of this type will be invoked as a function object and will be given all the unbound arguments passed to the bind-generated object.
目录 |
Inherited from std::integral_constant
Member constants
value [静态的]</div></div>
|
true如果 T is a function object generated by std::bind,false其他方式 原文: true if T is a function object generated by std::bind, false otherwise (公共静态成员常量) |
Member functions
operator bool |
转换的对象bool,返回 value 原文: converts the object to bool, returns value (公共成员函数) |
Member types
类型
|
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
</div>
[编辑] 示例
#include <iostream> #include <type_traits> #include <functional> struct MyBind { typedef int result_type; int operator()(int a, int b) const { return a + b; } }; namespace std { template<> struct is_bind_expression<MyBind> : public true_type {}; } int f(int n1, int n2) { return n1+n2; } int main() { // as if bind(f, bind(MyBind::operator(), _1, _2), 2) auto b = std::bind(f, MyBind(), 2); std::cout << "Adding 2 to the sum of 10 and 11 gives " << b(10, 11) << '\n'; }
输出:
Adding 2 to the sum of 10 and 11 gives 23
[编辑] 另请参阅
(C++11) |
绑定一个或多个参数的函数对象 原文: binds one or more arguments to a function object (函数模板) |