std::experi...e_expression(3)
π std::experimental::where_expression π
okay bestie, welcome to the manual page for std::experimental::where_expression, live from the C++ Standard Libary manual β yes, that exact spelling, sheβs iconic β and the page slug is std::experi...e_expression(3) because truncation is her whole brand. Every technical deet is staying exactly where it was, just with way more sparkle. β¨
π NAME π
std::experimental::where_expression - std::experimental::where_expression
β¨ Synopsis β¨
Defined in header <experimental/simd>
template< class M, class V > (parallelism TS v2)
class where_expression;
Okay so the class template where_expression abstracts the notion of selected elements of a given lvalue of arithmetic or data-parallel type. The selected elements are the elements of the lvalue (of type V) for which the corresponding element of the mask (of type M) is true. Operators applied to objects of type where_expression<M, V> are applied only to selected elements. All other elements are left unchanged. No cap.
Use the where function to construct where_expression objects. Thatβs the move. π«Ά
π¦ Template parameters π¦
Mβ the mask typeVβ the value typeMapplies on
Valid combinations of (M, V) are literally:
(simd_mask<T, Abi>, simd<T, Abi>),(simd_mask<T, Abi>, simd_mask<T, Abi>),(bool, T).
π Member functions π
operator=β assigns to selected positions (public member function)operator+=β compound operators (public member function)operator-=β compound operators (public member function)operator*=β compound operators (public member function)operator/=β compound operators (public member function)operator%=β compound operators (public member function)operator&=β compound operators (public member function)operator|=β compound operators (public member function)operator^=β compound operators (public member function)operator<<=β compound operators (public member function)operator>>=β compound operators (public member function)operator++β increment and decrement operators (public member function)operator--β increment and decrement operators (public member function)copy_fromβ loads from address to selected positions (public member function)
π Example π
The page says // Run this code, so hereβs the code, exactly:
// Run this code
#include <cstddef>
#include <experimental/simd>
#include <iostream>
namespace stdx = std::experimental;
void print(auto const& a)
{
for (std::size_t i{}; i != std::size(a); ++i)
std::cout << a[i] << ' ';
std::cout << '\n';
}
template<class A>
stdx::simd<int, A> my_abs(stdx::simd<int, A> x)
{
where(x < 0, x) = -x;
return x;
}
int main()
{
const stdx::native_simd<int> a([](int i) { return i - 2; });
print(a);
const auto b = my_abs(a);
print(b);
}
π Possible output π
-2 -1 0 1
2 1 0 1
Thatβs the whole vibe: source http://cppreference.com, version/date 2024.06.10, and footer slug std::experi...e_expression(3). Stay selected, bestie β the mask said true for you πβ¨π
π¦ 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