Namespaces
Variants

std:: negation

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
negation
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
定義先ヘッダ <type_traits>
template < class B >
struct negation ;
(C++17以降)

論理的否定 を型特性 B に対して形成します。

std :: negation < B > は、 UnaryTypeTrait であり、基本特性は std:: bool_constant < ! bool ( B :: value ) > です。

プログラムが std::negation または std::negation_v に対する特殊化を追加する場合、動作は未定義です。

目次

翻訳のポイント: - 「Contents」→「目次」に翻訳 - C++関連の専門用語(Template parameters、Helper variable template、std::integral_constant、Member constants、Member functions、Member types、Possible implementation、Notes、Example、See also)は原文のまま保持 - HTMLタグ、属性、構造は完全に保持 - 数値や記号類は変更なし

テンプレートパラメータ

B - bool ( B :: value ) が有効な定数式となる任意の型

ヘルパー変数テンプレート

template < class B >
constexpr bool negation_v = negation < B > :: value ;
(C++17以降)

std:: integral_constant から継承

メンバ定数

value
[static]
true B :: value メンバを持ち、かつ明示的に bool に変換した際に false となる場合は 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)> { };

注記

機能テスト マクロ 標準 機能
__cpp_lib_logical_traits 201510L (C++17) 論理演算子型特性

#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,
    "");
static_assert(std::negation_v<std::bool_constant<true>> == false);
static_assert(std::negation_v<std::bool_constant<false>> == true);
int main() {}

関連項目

可変長論理積メタ関数
(クラステンプレート)
可変長論理和メタ関数
(クラステンプレート)
指定された型と値を持つコンパイル時定数
(クラステンプレート)