Namespaces
Variants

std:: is_placeholder

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until 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 для типов не-заполнителей
(публичная статическая константа-член)

Функции-члены

operator int
преобразует объект в int , возвращает value
(публичная функция-член)
operator()
(C++14)
возвращает value
(публичная функция-член)

Типы-члены

Тип Определение
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)
связывает один или несколько аргументов с функциональным объектом
(шаблон функции)
заполнители для несвязанных аргументов в выражении std::bind
(константа)