std::is_bind_expression
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <functional> で定義
|
||
template< class T > struct is_bind_expression; |
(C++11以上) | |
T が std::bind の呼び出しによって生成される型の場合、このテンプレートは std::true_type から派生します。 それ以外のあらゆる型に対しては、このテンプレートは std::false_type から派生します。
このテンプレートは、 T が bind 部分式の型であるかのように std::bind によって取り扱われるべきであることを示すために std::true_type の BaseCharacteristic を持つ UnaryTypeTrait を実装するために、ユーザ定義型 T に対して特殊化しても構いません。 bind の生成した関数オブジェクトが呼び出されるとき、この型の束縛引数は関数オブジェクトとして呼び出され、 bind の生成したオブジェクトに渡される未束縛引数がすべて与えられます。
ヘルパー変数テンプレート
<tbody> </tbody> template< class T > inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value; |
(C++17以上) | |
std::integral_constant から継承
メンバ定数
value [静的] |
T が std::bind によって生成された関数オブジェクトならば true、そうでなければ false (パブリック静的メンバ定数) |
メンバ関数
operator bool |
オブジェクトを bool に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
| 型 | 定義 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
例
Run this code
#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(), _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) |
関数オブジェクトに1つ以上の引数をバインドします (関数テンプレート) |