タイププロパティ
type 属性は、型のプロパティをクエリまたは変更するためのコンパイル時のテンプレート ベースの構造を定義します。
<type_traits> ヘッダーで定義されたテンプレートを特殊化しようとすると、std::common_type が説明どおりに特殊化できる場合を除き、未定義の動作が発生します。
<type_traits> ヘッダー ファイルで定義されたテンプレートは、特に指定されない限り、不完全な型でインスタンス化できますが、不完全な型による標準ライブラリ テンプレートのインスタンス化は一般に禁止されています。
プロパティに対する操作
論理非要素関数
std::negation
テンプレート<クラス B> |
(1) | (C++17以降) |
type 属性の論理否定を構築しますB
。
型 std::negation単項型の特性 (UnaryTypeTrait) 。
テンプレートパラメータ
B | - | 式 bool(B::value) を有効な定数式にする任意の型 |
補助変数テンプレート
テンプレート |
(C++17以降) |
可能な実装
template<class B>
struct negation : std::bool_constant<!bool(B::value)> { };
std::integral_constant から継承
メンバー定数
価値 [静的] |
は、 B に があり、暗黙的に bool に変換される場合は false に等しく、それ以外の場合は false です。 a> (パブリック静的メンバー定数)::value |
メンバー関数
演算子ブール |
オブジェクトを bool に変換して返す value (パブリック メンバー関数) |
オペレーター() (C++14) |
return value (パブリック メンバー関数) |
メンバータイプ
タイプ | 意味 |
value_type |
bool |
type |
std::integral_constant |
通話例
#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;
}
出力
std::negation<std::bool_constant<true>>::value: false
std::negation<std::bool_constant<false>>::value: true