std::is_bounded_array
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T > struct is_bounded_array; |
(C++20 起) | |
std::is_bounded_array
是一個 一元型別特性。
檢查 `T` 是否是已知邊界的陣列型別。提供成員常量 `value`,如果 `T` 是已知邊界的陣列型別,則 `value` 等於 true。否則,`value` 等於 false。
如果程式為 `std::is_bounded_array` 或 `std::is_bounded_array_v` 新增特化,則行為未定義。
目錄 |
[編輯] 模板引數
T | - | 要檢查的型別 |
[編輯] 輔助變數模板
template< class T > constexpr bool is_bounded_array_v = is_bounded_array<T>::value; |
(C++20 起) | |
繼承自 std::integral_constant
成員常量
value [靜態] |
如果 `T` 是已知邊界的陣列型別,則為 true,否則為 false。 (public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
std::integral_constant<bool, value> |
[編輯部分:可能的實現] 可能的實現
template<class T> struct is_bounded_array : std::false_type {}; template<class T, std::size_t N> struct is_bounded_array<T[N]> : std::true_type {}; |
[編輯部分:備註] 備註
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_bounded_array_traits |
201902L |
(C++20) | std::is_bounded_array , std::is_unbounded_array |
[編輯部分:示例] 示例
執行此程式碼
#include <iostream> #include <type_traits> #define OUT(...) std::cout << #__VA_ARGS__ << " : " << __VA_ARGS__ << '\n' class A {}; int main() { std::cout << std::boolalpha; OUT(std::is_bounded_array_v<A>); OUT(std::is_bounded_array_v<A[]>); OUT(std::is_bounded_array_v<A[3]>); OUT(std::is_bounded_array_v<float>); OUT(std::is_bounded_array_v<int>); OUT(std::is_bounded_array_v<int[]>); OUT(std::is_bounded_array_v<int[3]>); }
輸出
std::is_bounded_array_v<A> : false std::is_bounded_array_v<A[]> : false std::is_bounded_array_v<A[3]> : true std::is_bounded_array_v<float> : false std::is_bounded_array_v<int> : false std::is_bounded_array_v<int[]> : false std::is_bounded_array_v<int[3]> : true
[編輯部分:另請參見] 另請參見
(C++11) |
檢查型別是否為陣列型別 (類模板) |
(C++20) |
檢查型別是否為未知邊界的陣列型別 (類模板) |
(C++11) |
獲取陣列型別在指定維度上的大小 (類模板) |