std::experimental:: is_simd, std::experimental:: is_simd_mask
|
定义于头文件
<experimental/simd>
|
||
|
template
<
class
T
>
struct is_simd ; |
(1) | (并行 TS v2) |
|
template
<
class
T
>
struct is_simd_mask ; |
(2) | (并行 TS 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
[static]
|
若
T
是
simd
/
simd_mask
类型则为
true
,否则为
false
(公开静态成员常量) |
成员函数
|
operator bool
|
转换对象为
bool
,返回
value
(公开成员函数) |
|
operator()
(C++14)
|
返回
value
(公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool |
type
|
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