std::experimental::is_simd, std::experimental::is_simd_mask
來自 cppreference.com
< cpp | experimental | simd
定義於標頭檔案 <experimental/simd> |
||
template< class T > struct is_simd; |
(1) | (並行技術規範 v2) |
template< class T > struct is_simd_mask; |
(2) | (並行技術規範 v2) |
目錄 |
[編輯] 模板引數
T | - | 要檢查的型別 |
[編輯] 輔助變數模板
template< class T > constexpr bool is_simd_v = is_simd<T>::value; |
(並行技術規範 v2) | |
template< class T > constexpr bool is_simd_mask_v = is_simd_mask<T>::value; |
(並行技術規範 v2) | |
繼承自 std::integral_constant
成員常量
value [靜態] |
若 T 為 simd /simd_mask 型別,則為 true,否則為 false(public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
std::integral_constant<bool, value> |
[編輯] 註解
is_simd_v<T> 是測試 T
是否可用作 SIMD 型別所必需的,但不是充分的條件。例如,is_simd_v<simd<bool>> 為 true,即使 bool 不在允許的向量化型別中。缺少的條件是 std::is_constructible_v<T>,它對於 simd<bool> 為 false。
[編輯] 示例
執行此程式碼
#include <experimental/simd> #include <iostream> #include <string_view> namespace stdx = std::experimental; template<typename T> void test_simd(std::string_view type_name) { std::cout << std::boolalpha << "Type: " << type_name << '\n' << " is_simd: " << stdx::is_simd_v<T> << '\n' << " is_constructible: " << std::is_constructible_v<T> << '\n'; } template<typename T> void test_simd_mask(std::string_view type_name) { std::cout << std::boolalpha << "Type: " << type_name << '\n' << " is_simd_mask: " << stdx::is_simd_mask_v<T> << '\n' << " is_constructible: " << std::is_constructible_v<T> << "\n\n"; } int main() { test_simd<int>("int"); test_simd_mask<int>("int"); test_simd<stdx::simd<float>>("simd<float>"); test_simd_mask<stdx::simd_mask<float>>("simd_mask<float>"); test_simd<stdx::simd<bool>>("simd<bool>"); test_simd_mask<stdx::simd_mask<bool>>("simd_mask<bool>"); }
輸出
Type: int is_simd: false is_constructible: true Type: int is_simd_mask: false is_constructible: true Type: simd<float> is_simd: true is_constructible: true Type: simd_mask<float> is_simd_mask: true is_constructible: true Type: simd<bool> is_simd: true is_constructible: false Type: simd_mask<bool> is_simd_mask: true is_constructible: false