Namespaces
Variants

std:: negation

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
negation
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
Definiert im Header <type_traits>
template < class B >
struct negation ;
(seit C++17)

Bildet die logische Negation des Typmerkmals B .

Der Typ std :: negation < B > ist ein UnaryTypeTrait mit einer Basiseigenschaft von std:: bool_constant < ! bool ( B :: value ) > .

Wenn das Programm Spezialisierungen für std::negation oder std::negation_v hinzufügt, ist das Verhalten undefiniert.

Inhaltsverzeichnis

Template-Parameter

B - jeder Typ, für den der Ausdruck bool ( B :: value ) ein gültiger konstanter Ausdruck ist

Hilfsvariablen-Template

template < class B >
constexpr bool negation_v = negation < B > :: value ;
(seit C++17)

Geerbt von std:: integral_constant

Member-Konstanten

value
[static]
true wenn B ein Member :: value besitzt, das bei expliziter Konvertierung zu bool false ergibt, andernfalls false
(öffentliche statische Member-Konstante)

Member-Funktionen

operator bool
konvertiert das Objekt zu bool , gibt value zurück
(öffentliche Member-Funktion)
operator()
(C++14)
gibt value zurück
(öffentliche Member-Funktion)

Member-Typen

Typ Definition
value_type bool
type std:: integral_constant < bool , value >

Mögliche Implementierung

template<class B>
struct negation : std::bool_constant<!bool(B::value)> { };

Hinweise

Feature-Test Makro Wert Std Feature
__cpp_lib_logical_traits 201510L (C++17) Logische Operator-Typ-Traits

Beispiel

#include <type_traits>
static_assert(
    std::is_same<
        std::bool_constant<false>,
        typename std::negation<std::bool_constant<true>>::type>::value,
    "");
static_assert(
    std::is_same<
        std::bool_constant<true>,
        typename std::negation<std::bool_constant<false>>::type>::value,
    "");
static_assert(std::negation_v<std::bool_constant<true>> == false);
static_assert(std::negation_v<std::bool_constant<false>> == true);
int main() {}

Siehe auch

variadische logische UND-Metafunktion
(Klassentemplate)
variadische logische ODER-Metafunktion
(Klassentemplate)
Kompilierzeitkonstante des angegebenen Typs mit angegebenem Wert
(Klassentemplate)