std::mask_array::operator=(3)
π std::mask_array::operator=(3) π
okay bestie, welcome to the C++ Standard Libary page for std::mask_array::operator=(3). This is the assignment operator for a mask_array, and there are three overloads. Letβs get into it β¨
π NAME π
std::mask_array::operator= β literally std::mask_array::operator=. Thatβs the name, bestie, no cap π
πΈ Synopsis πΈ
There are three overloads, and yes, all of them are const:
void operator=( const T& value ) const; (1)
void operator=( const std::valarray<T>& val_arr ) const; (2)
const mask_array& operator=( const mask_array& other_arr ) const; (3)
The whole vibe here: assigns values to all referred elements. Overload by overload:
- Assigns
valueto all of the elements. - Assigns the elements of
val_arrto the referred to elements of*this. - Assigns the selected elements from
other_arrto the referred to elements of*this.
π Parameters π
valueβ a value to assign to all of the referred elements.val_arrβstd::valarrayto assign.other_arrβstd::mask_arrayto assign.
π Return value π
1,2)β(none). No return, bestie.3)β*this. Yup, it returns itself.
π§ͺ Example π§ͺ
Run this code, bestie:
// Run this code
#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);
}
π₯οΈ Output π₯οΈ
1 0 3 0 5 0 7 0
-1 2 -2 4 -3 6 -4 8
1 1 3 3 5 5 7 7
π©Ή Defect reports π©Ή
okay so these behavior-changing defect reports were applied retroactively to previously published C++ standards β yes, retroactively, bestie:
- DR
LWG 123β applied toC++98; behavior as published: overload (2) was non-const; correct behavior: made const. - DR
LWG 253β applied toC++98; behavior as published: the copy assignment operator was private; correct behavior: made public. - DR
LWG 621β applied toC++98; behavior as published: the copy assignment operator was non-const; correct behavior: made const.
mwah π β footer sign-off time: source http://cppreference.com, version/date 2024.06.10, page std::mask_array::operator=(3). bye bestie, go assign something cute π«Άβ¨
π¦ 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