Namespaces
Variants

std::is_placeholder

ja.cppreference.net より
 
 
ユーティリティライブラリ
言語サポート
型サポート(基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変長引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
関数オブジェクト
関数呼び出し
(C++17)(C++23)
恒等関数オブジェクト
(C++20)
透過的演算子ラッパー
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

旧来のバインダとアダプタ
(C++17まで*)
(C++17まで*)
(C++17まで*)
(C++17まで*)  
(C++17まで*)
(C++17まで*)(C++17まで*)(C++17まで*)(C++17まで*)
(C++20まで*)
(C++20まで*)
(C++17まで*)(C++17まで*)
(C++17まで*)(C++17まで*)

(C++17まで*)
(C++17まで*)(C++17まで*)(C++17まで*)(C++17まで*)
(C++20まで*)
(C++20まで*)
 
ヘッダ <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つ以上の引数を関数オブジェクトにバインドする
(関数テンプレート)
std::bind 式内の未バインド引数のためのプレースホルダ
(定数)