std::mask_array<T>::operator=

Assigns values to all referred elements.

# Declarations

void operator=( const T& value ) const;
void operator=( const std::valarray<T>& val_arr ) const;
const mask_array& operator=( const mask_array& other_arr ) const;

# Parameters

# Example

#include <iomanip>
#include <iostream>
#include <valarray>
 
void print(std::valarray<int> const& v)
{
    for (int e : v)
        std::cout << std::setw(2) << e << ' ';
    std::cout << '\n';
}
 
int main()
{
    const auto init = {1, 2, 3, 4, 5, 6, 7, 8};
    std::valarray<int> v;
 
    v = init;
    v[(v % 2) == 0] = 0; // (1)
    print(v);
 
    v = init;
    v[(v % 2) == 1] = std::valarray<int>{-1, -2, -3, -4}; // (2)
    print(v);
 
    v = init;
    v[(v % 2) == 0] = v[(v % 2) == 1]; // (3)
    print(v);
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 123C++98overload (2) was non-constmade const
LWG 253C++98the copy assignment operator was privatemade public
LWG 621C++98the copy assignment operator was non-constmade const