std:: is_bind_expression
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<functional>
|
||
|
template
<
class
T
>
struct is_bind_expression ; |
(C++11 起) | |
如果
T
是通过调用
std::bind
(但不包括
std::bind_front
或
std::bind_back
)生成的类型,则该模板派生自
std::true_type
。对于任何其他类型(除非用户特化),该模板派生自
std::false_type
。
程序可为
程序定义类型
T
特化此模板,以实现
UnaryTypeTrait
,其基特征为
std::true_type
,以表明
T
应当被
std::bind
视为绑定子表达式类型:当调用由 bind 生成的函数对象时,该类型的绑定参数将被作为函数对象调用,并接收所有传递给 bind 生成对象的未绑定参数。
目录 |
辅助变量模板
|
template
<
class
T
>
constexpr bool is_bind_expression_v = is_bind_expression < T > :: value ; |
(C++17 起) | |
继承自 std:: integral_constant
成员常量
|
value
[static]
|
若
T
是由
std::bind
生成的函数对象则为
true
,否则为
false
(公开静态成员常量) |
成员函数
|
operator bool
|
转换对象为
bool
类型,返回
value
(公开成员函数) |
|
operator()
(C++14)
|
返回
value
(公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
示例
#include <functional> #include <iostream> #include <type_traits> 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() { // 效果等同于 bind(f, bind(MyBind(), _1, _2), 2) auto b = std::bind(f, MyBind(), 2); std::cout << "将2与10和11的和相加得到 " << b(10, 11) << '\n'; }
输出:
将2与10和11的和相加得到 23
缺陷报告
下列行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 应用于 | 发布时的行为 | 正确行为 |
|---|---|---|---|
| LWG 2010 | C++11 |
程序定义的特化只能
继承自 std::false_type |
可以继承自
std::true_type |
参见
|
(C++11)
|
将一个或多个参数绑定到函数对象
(函数模板) |