std::mask_array<T>::operator=
來自 cppreference.com
< cpp | 數值 | valarray | mask array
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 | 複製賦值運算子為私有 | 改為公有 |
LWG 621 | C++98 | 複製賦值運算子為非 const | 改為 const |