名稱空間
變體
操作

std::is_placeholder

來自 cppreference.com
 
 
 
函式物件
部分函式應用
(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,以實現 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
[靜態]
佔位符值或非佔位符型別的 0
(public static 成員常量)

成員函式

operator int
將物件轉換為 int,返回 value
(公開成員函式)
operator()
(C++14)
返回 value
(公開成員函式)

成員型別

型別 定義
value_type int
型別 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)
將一個或多個引數繫結到函式物件
(函式模板) [編輯]
std::bind 表示式中未繫結引數的佔位符
(常數) [編輯]