Namespaces
Variants

std::indirect_array<T>:: operator=

From cppreference.net

void operator = ( const T & value ) const ;
(1)
void operator = ( const std:: valarray < T > & val_arr ) const ;
(2)
const indirect_array & operator = ( const indirect_array & other_arr ) const ;
(3)

참조된 모든 요소에 값을 할당합니다.

1) 모든 요소에 value 를 할당합니다.
2) val_arr 의 요소들을 * this 가 참조하는 요소들에 할당합니다.
3) other_arr 에서 선택된 요소들을 * this 가 참조하는 요소들에 할당합니다.

목차

매개변수

value - 참조된 모든 요소에 할당할 값
val_arr - std::valarray 할당할 배열
other_arr - std::indirect_array 할당할 간접 배열

반환값

1,2) (없음)
3) * this

예제

#include <iomanip>
#include <iostream>
#include <numeric>
#include <valarray>
void print(int n, std::valarray<int> const& v)
{
    std::cout << n << ':';
    for (int e : v)
        std::cout << std::setw(3) << e;
    std::cout << '\n';
}
int main()
{
    std::valarray<int> v(8);
    std::iota(std::begin(v), std::end(v), 0);
    print(1, v);
    std::valarray<std::size_t> idx{1, 3, 5, 7};
    const std::indirect_array<int> ia = v[idx];
    // 'ia'는 v[1], v[3], v[5], v[7]을 참조합니다
    ia = -1; // (1), 효과적으로:
             // v[1] = v[3] = v[5] = v[7] = -1;
    print(2, v);
    ia = /*std::valarray<int>*/{-1, -2, -3, -4}; // (2),
        // 효과적으로: v[1] = -1, v[3] = -2, v[5] = -3, v[7] = -4;
    print(3, v);
    std::valarray<std::size_t> idx2{0, 2, 4, 6};
    const std::indirect_array<int> ia2 = v[idx2];
    // 'ia2'는 v[0], v[2], v[4], v[6]을 참조합니다
    ia = ia2; // (3), 효과적으로:
              // v[1] = v[0], v[3] = v[2], v[5] = v[4], v[7] = v[6];
    print(4, v);
}

출력:

1:  0  1  2  3  4  5  6  7
2:  0 -1  2 -1  4 -1  6 -1
3:  0 -1  2 -2  4 -3  6 -4
4:  0  0  2  2  4  4  6  6

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 123 C++98 overload (2) was non-const made const
LWG 253 C++98 the copy assignment operator was private made public
LWG 621 C++98 the copy assignment operator was non-const made const