std::negation
來自 cppreference.com
| 定義於標頭檔案 <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 新增特化,則行為未定義。
目錄 |
[編輯] 模板引數
| 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() {}
[編輯] 參閱
| (C++17) |
可變引數邏輯 AND 元函式 (類模板) |
| (C++17) |
可變引數邏輯 OR 元函式 (類模板) |
| (C++11)(C++17) |
指定型別和指定值的編譯時常量 (類模板) |