std:: is_placeholder
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定義先ヘッダ
<functional>
|
||
|
template
<
class
T
>
struct is_placeholder ; |
(C++11以降) | |
T
が標準プレースホルダ
(_1, _2, _3, ...)
の型である場合、このテンプレートはそれぞれ
std::
integral_constant
<
int
,
1
>
、
std::
integral_constant
<
int
,
2
>
、
std::
integral_constant
<
int
,
3
>
から派生します。
T
が標準のプレースホルダ型でない場合、このテンプレートは
std::
integral_constant
<
int
,
0
>
から派生します。
プログラムは、プログラム定義型
T
に対してこのテンプレートを特殊化し、
UnaryTypeTrait
を実装できます。その際、基底特性として
std::
integral_constant
<
int
, N
>
を正の値
N
で指定することで、
T
が
N
番目の
プレースホルダ型として扱われるべきであることを示します。
std::bind
は、未束縛引数のプレースホルダーを検出するために
std::is_placeholder
を使用します。
目次 |
ヘルパー変数テンプレート
|
template
<
class
T
>
constexpr int is_placeholder_v = is_placeholder < T > :: value ; |
(C++17以降) | |
std::integral_constantから継承
メンバ定数
|
value
[static]
|
プレースホルダーの値、または非プレースホルダー型の場合は
0
(public static member constant) |
メンバ関数
|
operator int
|
オブジェクトを
int
に変換し、
value
を返す
(public member function) |
|
operator()
(C++14)
|
value
を返す
(public member function) |
メンバ型
| 型 | 定義 |
value_type
|
int |
type
|
std:: integral_constant < int , value > |
例
#include <functional> #include <iostream> #include <type_traits> struct My_2 {} my_2; namespace std { template<> struct is_placeholder<My_2> : public integral_constant<int, 2> {}; } int f(int n1, int n2) { return n1 + n2; } int main() { std::cout << "Standard placeholder _5 is for the argument number " << std::is_placeholder_v<decltype(std::placeholders::_5)> << '\n'; auto b = std::bind(f, my_2, 2); std::cout << "Adding 2 to 11 selected with a custom placeholder gives " << b(10, 11) // the first argument, namely 10, is ignored << '\n'; }
出力:
Standard placeholder _5 is for the argument number 5 Adding 2 to 11 selected with a custom placeholder gives 13
関連項目
|
(C++11)
|
1つ以上の引数を関数オブジェクトにバインドする
(関数テンプレート) |
|
(C++11)
|
std::bind
式内の未バインド引数のためのプレースホルダ
(定数) |