type properties
A type attribute defines a compile-time template-based structure for querying or modifying the properties of a type.
Attempting to specialize a template defined in the <type_traits> header causes undefined behavior, except that std::common_type can be specialized as described.
Templates defined in the <type_traits> header file may be instantiated with incomplete types unless otherwise specified, although instantiation of standard library templates with incomplete types is generally prohibited.
operations on properties
Logical non-element function
std::negation
template<class B> |
(1) | (since C++17) |
Constructs the logical negation of type attribute B
.
The type std::negation<B> is the base characteristic (BaseCharacteristic) of std::bool_constant<!bool(B::value)>The unary type characteristic a> (UnaryTypeTrait) .
Template parameters
B | - | Any type that makes the expression bool(B::value) a legal constant expression |
Auxiliary variable template
template<class B> |
(since C++17) |
Possible implementation
template<class B>
struct negation : std::bool_constant<!bool(B::value)> { };
Inherited from std::integral_constant
member constants
value [static] |
is true if B has which is equal to false when implicitly converted to bool , false otherwise (Public static member constants)::value |
member function
operator bool |
Convert the object to bool and return value (public member function) |
operator() (C++14) |
return value (public member function) |
member type
type | definition |
value_type |
bool |
type |
std::integral_constant<bool, value> |
Call example
#include <iostream>
#include <type_traits>
namespace std
{
template <bool B>
using bool_constant = integral_constant<bool, B>;
template<class B>
struct negation : std::bool_constant < !bool(B::value) > { };
}
int main()
{
std::cout << std::boolalpha;
std::cout << "std::negation<std::bool_constant<true>>::value: "
<< std::negation<std::bool_constant<true>>::value << std::endl;
std::cout << "std::negation<std::bool_constant<false>>::value: "
<< std::negation<std::bool_constant<false>>::value << std::endl;
return 0;
}
output
std::negation<std::bool_constant<true>>::value: false
std::negation<std::bool_constant<false>>::value: true