首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_placeholder

Defined in header <functional>

?

?

template< class T > struct is_placeholder;

?

(since C++11)

如果T是标准占位符%28的类型。[医]1,[医]2,[医]3,%29,然后从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%第二十七占位符类型。

std::bind使用std::is_placeholder若要检测未绑定参数的占位符,请执行以下操作。

辅助变量模板

template< class T > inline constexpr bool is_placeholder_v = is_placeholder<T>::value;

?

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

placeholder value or 0 for non-placeholder types (public static member constant)

成员函数

operator int

converts the object to int, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

int

type

std::integral_constant<int, value>

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
Standard placeholder _5 is for the argument number 5
Adding 2 to 11 selected with a custom placeholder gives 13

二次

另见

bind (C++11)

binds one or more arguments to a function object (function template)

_1, _2, _3, _4, ... (C++11)

placeholders for the unbound arguments in a std::bind expression (constant)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com