Group Logical Values
Tags for representing true and false.
Tags for representing true and false.
Grouped Tags Overview
-
struct False;, False::Type;, bool False::VALUE = false;
Representation for False. -
struct True;, True::Type;, bool True::VALUE = true;
Representation for True.
Detailed Description
Examples
Print the values of the tags/metafunctions True and False.
std::cout << False::VALUE << "\n" // => "0"
<< True::VALUE << "\n" // => "1"
<< IsSameType<False, False::Type>::VALUE << "\n"; // => "1"
Snippet from: demos/dox/basic/metaprogramming_logic.cpp
Inheriting from True and False
The two tags True and False have the special property that they can also be used as metafunctions and both have a VALUE as well as a TYPE. This property makes it very convenient to define metafunctions by inheriting from the True or False.
template <typename T>
struct IsInt32 :
False {};
template <>
struct IsInt32<int>:
True {};
Snippet from: demos/dox/basic/metaprogramming_logic.cpp
The metafunction IsInt32 can now be used as follows.
std::cout << IsInt32<bool>::VALUE << "\n" // => "0"
<< IsInt32<int>::VALUE << "\n"; // => "1"
Snippet from: demos/dox/basic/metaprogramming_logic.cpp