名稱空間
變體
操作

std::negation

來自 cppreference.com
< cpp‎ | 型別
 
 
超程式設計庫
型別特性
型別類別
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
型別屬性
(C++11)
(C++11)
(C++14)
(C++11)(C++26 中已棄用)
(C++11)(直到 C++20*)
(C++11)(C++20 中已棄用)
(C++11)
型別特性常量
元函式
negation
(C++17)
支援的操作
關係與屬性查詢
型別修改
(C++11)(C++11)(C++11)
型別轉換
(C++11)(C++23 中已棄用)
(C++11)(C++23 中已棄用)
(C++11)
(C++11)(直到 C++20*)(C++17)

(C++11)
(C++17)
編譯時有理數算術
編譯時整數序列
 
定義於標頭檔案 <type_traits>
template< class B >
struct negation;
(C++17 起)

形成型別特性 B邏輯非

型別 std::negation<B> 是一個 一元型別特性 (UnaryTypeTrait),其基本特性為 std::bool_constant<!bool(B::value)>

如果程式為 std::negationstd::negation_v 新增特化,則行為未定義。

目錄

[編輯] 模板引數

B - 任何型別,使得表示式 bool(B::value) 是有效的常量表達式。

[編輯] 輔助變數模板

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

繼承自 std::integral_constant

成員常量

value
[靜態]
如果 B 有一個成員 ::value,且當它被顯式轉換為 bool 時為 false,則為 true,否則為 false
(public static 成員常量)

成員函式

operator bool
將物件轉換為 bool,返回 value
(公開成員函式)
operator()
(C++14)
返回 value
(公開成員函式)

成員型別

型別 定義
value_type bool
型別 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() {}

[編輯] 參閱

可變引數邏輯 AND 元函式
(類模板) [編輯]
可變引數邏輯 OR 元函式
(類模板) [編輯]
指定型別和指定值的編譯時常量
(類模板) [編輯]
English 日本語 中文(简体) 中文(繁體)