namespace std { template <class Trait> struct negation; template <class Trait> constexpr bool negation_v = negation<Trait>::value; }
概要
特性(bool値を返すメタ関数)の論理否定を計算する。
要件
Traitはboolに変換可能なメンバ変数valueを持つこと。
効果
bool_constant<!Trait::value>
から派生する。
すなわち、Trait::value == true
ならばfalse_type
から派生し、Trait::value == false
ならばtrue_type
から派生する。
例
#include <type_traits> #include <iostream> template<typename T> void f() { std::cout << std::boolalpha << "T::value = " << T::value << std::endl; } int main() { f<std::is_integral<int>>(); f<std::negation<std::is_integral<int>>>(); }
出力
T::value = true
T::value = false
実装例
template <class Trait> struct negation : bool_constant<!Trait::value> {};
バージョン
言語
- C++17
処理系
- Clang: 3.8
- GCC: 6.3
- Visual C++: 2015 update2, 2017
negation_v
は、2015 update3までは定義されているが有効化されていない。