名前空間
変種
操作

std::is_placeholder

From cppreference.com
< cpp‎ | utility‎ | functional
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
関数オブジェクト
部分関数適用
(C++20)(C++23)
(C++11)
is_placeholder
(C++11)
関数の呼び出し
(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 に対してこのテンプレートを特殊化することで、UnaryTypeTraitstd::integral_constant<int, N> を基底特性とし、T を N 番目のプレースホルダ型として扱うことを示す正の 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
(公開静的メンバ定数)

メンバ関数

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 式における未束縛の引数のためのプレースホルダ
(定数) [編集]
English 日本語 中文(简体) 中文(繁體)