std::is_placeholder
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <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 に対して特殊化しても構いません。 この特殊化は T が N 番目のプレースホルダー型として扱われるべきであることを示すために N > 0 である std::integral_constant<int, N> の BaseCharacteristic を持つ UnaryTypeTrait を満たさなければなりません。
std::bind は未束縛引数のためのプレースホルダーを検出するために std::is_placeholder を使用します。
ヘルパー変数テンプレート
<tbody> </tbody> template< class T > inline constexpr int is_placeholder_v = is_placeholder<T>::value; |
(C++17以上) | |
std::integral_constant から継承
メンバ定数
value [静的] |
プレースホルダーの値、または非プレースホルダー型に対しては 0 (パブリック静的メンバ定数) |
メンバ関数
operator int |
オブジェクトを int に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
| 型 | 定義 |
value_type
|
int
|
type
|
std::integral_constant<int, value>
|
例
Run this code
#include <iostream>
#include <type_traits>
#include <functional>
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<decltype(std::placeholders::_5)>::value
<< '\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 式におけるバインドされない引数のためのプレースホルダ (定数) |