std::negation
提供: cppreference.com
ヘッダ <type_traits> で定義
|
||
template<class B> struct negation; |
(1) | (C++17以上) |
型特性 B
の論理否定を形成します。
型 std::negation<B> は std::bool_constant<!bool(B::value)> の BaseCharacteristic を持つ UnaryTypeTrait です。
目次 |
[編集] テンプレート引数
B | - | 式 bool(B::value) が有効な定数式であるような任意の型 |
[編集] ヘルパー変数テンプレート
template<class B> inline constexpr bool negation_v = negation<B>::value; |
(C++17以上) | |
std::integral_constant から継承
メンバ定数
value [静的] |
明示的に bool に変換されたとき false であるメンバ ::value を B が持つならば true、そうでなければ false (パブリック静的メンバ定数) |
メンバ関数
operator bool |
オブジェクトを bool に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
型 | 定義 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
[編集] 実装例
template<class B> struct negation : std::bool_constant<!bool(B::value)> { }; |
[編集] 例
Run this code
#include <iostream> #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, ""); int main() { std::cout << std::boolalpha; std::cout << std::negation<std::bool_constant<true>>::value << '\n'; std::cout << std::negation<std::bool_constant<false>>::value << '\n'; }
出力:
false true
[編集] 関連項目
(C++17) |
可変個引数の論理積メタ関数 (クラステンプレート) |
(C++17) |
可変個引数の論理和メタ関数 (クラステンプレート) |
(C++11)(C++17) |
指定された値を持つ指定された型のコンパイル時定数 (クラステンプレート) |