CppDS.com

C++ 98 11 14 17 20 手册

std::is_placeholder

来自cppreference.com
< cpp‎ | utility‎ | functional
 
 
工具库
通用工具
日期和时间
函数对象
格式化库 (C++20)
(C++11)
关系运算符 (C++20 中弃用)
整数比较函数
(C++20)
swap 与类型运算
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
常用词汇类型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等字符串转换
(C++17)
(C++17)
 
函数对象
函数包装
(C++11)
(C++11)
部分函数应用
(C++11)
(C++20)
is_placeholder
(C++11)
函数调用
(C++17)
恒等函数对象
(C++20)
引用包装
(C++11)(C++11)
运算符包装
取反器
(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 > 0 指示 T 应被处理成第 N 个占位符类型的基特征 (BaseCharacteristic)

std::bindstd::is_placeholder 检测未绑定参数的占位符。

辅助变量模板

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>

示例

#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) // 忽略首参数,即 10
              << '\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 表达式中的未绑定实参的占位符
(常量)
关闭