std::is_placeholder
来自cppreference.com
< cpp | utility | functional
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <functional> 中定义
|
||
template< class T > struct is_placeholder; |
(C++11 起) | |
T
是一个标准的占位符的类型(_1,_2,_3,...),那么这个模板std::integral_constant<int,1>,std::integral_constant<int,2>,std::integral_constant<int,3>,分别是来自。 T
是不是一个标准的占位符类型,此模板来自std::integral_constant<int,0>.原文:
If
T
is the type of a standard placeholder (_1, _2, _3, ...), then this template is derived from std::integral_constant<int,1>, std::integral_constant<int,2>, std::integral_constant<int,3>, respectively. If T
is not a standard placeholder type, this template is derived from std::integral_constant<int,0>.模板可以专门用于任何用户定义的类型,如果它是一个未绑定的参数占位符,应被视为由std::bind.
原文:
The template may be specialized for any user-defined type which should be treated by std::bind as if it was a placeholder for unbound arguments.
目录 |
Inherited from std::integral_constant
Member constants
value [静态的]</div></div>
|
placeholder value or 0 for non-placeholder types (公共静态成员常量) |
Member functions
operator int |
转换的对象int,返回 value 原文: converts the object to int, returns value (公共成员函数) |
Member types
类型
|
Definition |
value_type
|
int
|
type
|
std::integral_constant<int, value> |
</div>
[编辑] 示例
#include <iostream> #include <type_traits> #include <functional> struct My_2 { } my_2; namespace std { template<> struct is_placeholder<My_2> : public integral_constant<int, 2> {}; } int f(int n1, int n2) { return n1+n2; } int main() { std::cout << "Standard placeholder _5 is for the argument number " << std::is_placeholder<decltype(std::placeholders::_5)>::value << '\n'; auto b = std::bind(f, my_2, 2); std::cout << "Adding 2 to 11 selected with a custom placeholder gives " << b(10, 11) << '\n'; }
输出:
Standard placeholder _5 is for the argument number 5 Adding 2 to 11 selected with a custom placeholder gives 13
[编辑] 另请参阅
(C++11) |
绑定一个或多个参数的函数对象 原文: binds one or more arguments to a function object (函数模板) |
(C++11) |
std::bind 表达在未绑定的参数的占位符 原文: placeholders for the unbound arguments in a std::bind expression (常量) |