名前空間
変種
操作

std::negation

提供: cppreference.com
< cpp‎ | types
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
型サポート
型の性質
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++20未満)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
negation
(C++17)
定数評価文脈
サポートされている操作
関係と性質の問い合わせ
型変更
(C++11)(C++11)(C++11)
型変換
(C++11)
(C++11)
(C++17)
(C++11)(C++20未満)(C++17)
 
ヘッダ <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 であるメンバ ::valueB が持つならば 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)> { };

[編集]

#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

[編集] 関連項目

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