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
によってバインド部分式の型として扱われるべきであることを示します。つまり、バインドによって生成された関数オブジェクトが呼び出されるとき、この型のバインドされた引数は関数オブジェクトとして呼び出され、バインド生成オブジェクトに渡されたすべての未バインド引数が与えられます。
目次 |
ヘルパー変数テンプレート
|
template
<
class
T
>
constexpr bool is_bind_expression_v = is_bind_expression < T > :: value ; |
(C++17以降) | |
std:: integral_constant から継承
メンバ定数
|
value
[static]
|
true
(
T
が
std::bind
によって生成された関数オブジェクトの場合)、
false
(それ以外の場合)
(public static member constant) |
メンバ関数
|
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つ以上の引数を関数オブジェクトにバインドする
(関数テンプレート) |