std::is_bind_expression
From cppreference.com
< cpp | utility | functional
| ヘッダ <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によって生成された関数オブジェクトが呼び出されるとき、この型の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 を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
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() { // 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++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 2010 | C++11 | プログラム定義の特殊化は std::false_typeからしか派生できなかった |
派生できる std::true_type |
[編集] 関連項目
| (C++11) |
1つ以上の引数を関数オブジェクトに束縛する (関数テンプレート) |