首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_bind_expression

Defined in header <functional>

template< class T > struct is_bind_expression;

(since C++11)

如果T的调用生成的类型。std::bind,此模板派生自std::true_type对于任何其他类型,此模板派生自std::false_type...

此模板可专门用于用户定义的类型。T实施UnaryTypeTrait带着基本特征std::true_type以表明T应由std::bind就好像它是绑定子表达式的类型:当调用绑定生成的函数对象时,该类型的绑定参数将作为函数对象被调用,并将被赋予传递给绑定生成对象的所有未绑定参数。

辅助变量模板

template< class T > inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value;

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

true if T is a function object generated by std::bind, false otherwise (public static member constant)

成员函数

operator bool

converts the object to bool, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

bool

type

std::integral_constant<bool, value>

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
Adding 2 to the sum of 10 and 11 gives 23

二次

另见

bind (C++11)

binds one or more arguments to a function object (function template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券