std::experi...s_simd_mask(3)
πΈ std::experimental::is_simd, std::experimental::is_simd_mask πΈ
okay bestie so this is from the C++ Standard Libary manual, section 3, and it's genuinely one of those pages where the whole personality is "am I a SIMD type or not" β and honestly? iconic. Let's get into it π
β¨ NAME β¨
std::experimental::is_simd, std::experimental::is_simd_mask β literally just std::experimental::is_simd, std::experimental::is_simd_mask. That's the name. Periodt π«Ά
β¨ SYNOPSIS β¨
so this whole thing lives in the header <experimental/simd> π
template< class T > (1) (parallelism TS v2)
struct is_simd;
template< class T > (2) (parallelism TS v2)
struct is_simd_mask;
- bestie, if
Tis a specialization of thesimdclass template, then this provides the member constantvalueequaltrue. For literally any other type,valueisfalse. that's the whole job π - and if
Tis a specialization of thesimd_maskclass template, it provides the member constantvalueequaltrue. For any other type,valueisfalse. slay β¨
β¨ TEMPLATE PARAMETERS β¨
Tβ a type to check π
π Helper variable template π
template< class T >
(parallelism TS v2)
inline constexpr bool is_simd_v = is_simd<T>::value;
template< class T >
(parallelism TS v2)
inline constexpr bool is_simd_mask_v = is_simd_mask<T>::value;
β¨ INHERITED FROM std::integral_constant β¨
π¦ Member constants π¦
valueβtrueifTis asimd/simd_masktype,falseotherwise.[static](public static member constant) β
π¦ Member functions π¦
operator boolβ converts the object tobool, returnsvalue(public member function) πoperator()β returnsvalue(C++14) (public member function) π
π¦ Member types π¦
value_typeβbooltypeβstd::integral_constant<bool, value>
π NOTES π
okay this is the part you actually need to read, ngl. is_simd_v<T> is necessary but not sufficient for testing whether T can be used as a SIMD type π
for example, is_simd_v<simd<bool>> is true, even though bool is not included in the permissible vectorizable types. the missing condition is std::is_constructible_v<T>, which is false for simd<bool>. so yeah β vibe check twice, bestie π
π₯ EXAMPLE π₯
// Run this code
#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>");
}
β Output β
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
see how simd<bool> is like "yes I'm a simd" but "no I'm not constructible"? that's the whole note. that's the drama. i told you so π
and that's the page!! πβ¨ππ¦πΈπ
π«Ά sourced from http://cppreference.com, dated 2024.06.10, and yeah that's the std::experi...s_simd_mask(3) footer β go forth and type-trait responsibly, bestie π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms