std::mask_array<T>:: operator=
From cppreference.net
<
cpp
|
numeric
|
valarray
|
mask array
C++
Numerics library
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (
valarray
)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::mask_array
| Member functions | ||||
|
mask_array::operator=
|
||||
|
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) | |
为所有被引用的元素赋值。
1)
将
value
赋值给所有元素。
2)
将
val_arr
的元素赋值给
*
this
所指向的元素。
3)
将
other_arr
中选定的元素赋值给
*
this
所指向的元素。
目录 |
参数
| value | - | 要赋值给所有被引用元素的值 |
| val_arr | - | 要赋值的 std::valarray |
| other_arr | - | 要赋值的 std::mask_array |
返回值
1,2)
(无)
3)
*
this
示例
运行此代码
#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); }
输出:
1 0 3 0 5 0 7 0 -1 2 -2 4 -3 6 -4 8 1 1 3 3 5 5 7 7
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 适用版本 | 发布时行为 | 正确行为 |
|---|---|---|---|
| LWG 123 | C++98 | 重载 (2) 为非 const | 改为 const |
| LWG 253 | C++98 | 拷贝赋值运算符为 private | 改为 public |
| LWG 621 | C++98 | 拷贝赋值运算符为非 const | 改为 const |