##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::mask_array

From cppreference.com
< cpp‎ | numeric‎ | valarray

Defined in header `<valarray>` |  |
template< class T > class mask_array; |  |

`std::gslice_array` is a helper template used by std::mask_array subscript operator. It has reference semantics to a subset of the array specified by an mask array (std::valarray<bool> object).

### [edit] Member types

Type | Definition
`value_type` | `T`

### [edit] Member functions

(constructor) | constructs a `mask_array` (public member function) [edit]
(destructor) | destroys a `mask_array` (public member function) [edit]
operator= | assigns contents (public member function) [edit]
operator+=operator-=operator*=operator/=operator%=operator&=operator|=operator^=operator<<=operator>>= | performs arithmetic operation on the array referred by mask. (public member function) [edit]

### [edit] Example

Run this code

    #include <iostream>
    #include <valarray>

    int main()
    {
        std::valarray<int> data = {0,1,2,3,4,5,6,7,8,9};

        std::cout << "Initial valarray: ";
        for(int n: data) std::cout << n << ' ';
        std::cout << '\n';

        data[data > 5] = -1;
        // the type of data>5 is std::valarray<bool>
        // the type of data[data>5] is std::mask_array<int>

        std::cout << "After v[v>5]=-1:  ";
        for(int n: data) std::cout << n << ' ';
        std::cout << '\n';
    }

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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/numeric/valarray/mask_array&oldid=64116"