std::is_volatile
出自 cppreference.com
| 定義於標頭檔 <type_traits> |
||
| template< class T > struct is_volatile; |
(C++11 起) | |
std::is_volatile 是一個 UnaryTypeTrait(單元類型特徵)。
若 T 為 volatile 限定類型(即 volatile 或 const volatile),則提供成員常數 value 等於 true。對於任何其他類型,value 為 false。
若程式為 std::is_volatile 或 std::is_volatile_v 加入特化版本,則行為未定義。
目錄 |
[編輯] 模板參數
| T | - | 要檢查的類型 |
[編輯] 輔助變數模板
| template< class T > constexpr bool is_volatile_v = is_volatile<T>::value; |
(自 C++17 起) | |
繼承自 std::integral_constant
成員常數
| value [靜態] |
若 T 為 volatile 限定類型則為 true,否則為 false(公開靜態成員常數) |
成員函式
| operator bool |
將物件轉換為 bool,回傳 value (公開成員函式) |
| operator() (C++14) |
回傳 value (公開成員函式) |
成員型別
| 類型 | 定義 |
value_type
|
bool |
type (型別)
|
std::integral_constant<bool, value> |
[編輯] 可能的實作方式
template<class T> struct is_volatile : std::false_type {}; template<class T> struct is_volatile<volatile T> : std::true_type {}; |
[編輯] 範例
執行此程式碼
#include <type_traits> #include <valarray> static_assert(!std::is_volatile_v<int>); static_assert(std::is_volatile_v<volatile int>); static_assert(std::is_volatile_v<volatile const int>); static_assert(std::is_volatile_v<volatile std::valarray<float>>); static_assert(!std::is_volatile_v<std::valarray<volatile float>>); int main() {}
[編輯] 參見
| (C++11) |
檢查型別是否具有 const 限定修飾 (類別模板) |