std::mask_array
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Numerics library 
  
 
 
 
 
 
 
 Mathematical special functions (C++17)
 Mathematical constants (C++20)
 Basic linear algebra algorithms (C++26)
 Data-parallel types (SIMD) (C++26)
 Floating-point environment (C++11)
 Bit manipulation (C++20)
 Saturation arithmetic (C++26)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
std::valarray 
std::mask_array
 Member functions
Defined in header 
 
 
<valarray> 
 template< class T > class mask_array;
 
 
std::mask_array is a helper template used by the valarray subscript operator with std::valarray <bool> argument. It has reference semantics and provides access to the subset of the valarray consisting of the elements whose indices correspond to true values in the std::valarray <bool> mask.
[edit] Member types
 Type
 Definition
value_type
 T
[edit] Member functions
[edit] Example
Run this code
#include <iostream> #include <valarray> void println(auto rem, const auto& data) { for (std::cout << rem; int n : data) std::cout << n << ' '; std::cout << '\n'; } int main() { std::valarray <int> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; println("Initial valarray: ", data); data[data > 5] = -1; // the type of data>5 is std::valarray<bool> // the type of data[data>5] is std::mask_array<int> println("After v[v>5]=-1: ", data); }
Output:
Initial valarray: 0 1 2 3 4 5 6 7 8 9 After v[v>5]=-1: 0 1 2 3 4 5 -1 -1 -1 -1
[edit] See also
(C++26)
basic_simd_mask that can specify its width(alias template)[edit]