A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../ranges/../numeric/valarray/mask_array.html below:

std::mask_array - cppreference.com

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
#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 convenience alias template for basic_simd_mask that can specify its width
(alias template)[edit] data-parallel type with the element type bool
(class template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4