std:: is_placeholder
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definiert im Header
<functional>
|
||
|
template
<
class
T
>
struct is_placeholder ; |
(seit C++11) | |
Wenn
T
der Typ eines Standard-Platzhalters
(_1, _2, _3, ...)
ist, dann ist diese Vorlage abgeleitet von
std::
integral_constant
<
int
,
1
>
,
std::
integral_constant
<
int
,
2
>
,
std::
integral_constant
<
int
,
3
>
, jeweils.
Wenn
T
kein Standard-Platzhaltertyp ist, ist diese Vorlage abgeleitet von
std::
integral_constant
<
int
,
0
>
.
Ein Programm kann diese Vorlage für einen
programmdefinierten Typ
T
spezialisieren, um
UnaryTypeTrait
mit Basiseigenschaft
std::
integral_constant
<
int
, N
>
mit positivem
N
zu implementieren, um anzuzeigen, dass
T
als
N
-ter
Platzhaltertyp behandelt werden sollte.
std::bind
verwendet
std::is_placeholder
, um Platzhalter für ungebundene Argumente zu erkennen.
Inhaltsverzeichnis |
Hilfsvariablen-Template
|
template
<
class
T
>
constexpr int is_placeholder_v = is_placeholder < T > :: value ; |
(seit C++17) | |
Geerbt von std:: integral_constant
Member-Konstanten
|
value
[static]
|
Platzhalterwert oder
0
für Nicht-Platzhalter-Typen
(öffentliche statische Member-Konstante) |
Member-Funktionen
|
operator int
|
konvertiert das Objekt zu
int
, gibt
value
zurück
(öffentliche Member-Funktion) |
|
operator()
(C++14)
|
gibt
value
zurück
(öffentliche Member-Funktion) |
Member-Typen
| Typ | Definition |
value_type
|
int |
type
|
std:: integral_constant < int , value > |
Beispiel
#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'; }
Ausgabe:
Standard placeholder _5 is for the argument number 5 Adding 2 to 11 selected with a custom placeholder gives 13
Siehe auch
|
(C++11)
|
bindet ein oder mehrere Argumente an ein Funktionsobjekt
(Funktions-Template) |
|
(C++11)
|
Platzhalter für die ungebundenen Argumente in einem
std::bind
-Ausdruck
(Konstante) |