Сделаем перемещение члена и продление жизни гарантировано в моем случаеC++

Программы на C++. Форум разработчиков
Anonymous
 Сделаем перемещение члена и продление жизни гарантировано в моем случае

Сообщение Anonymous »

Вот фрагмент кода:

Код: Выделить всё

#include 
#include 

struct Matrix
{
struct Proxy
{
Proxy(Matrix& m) : m_ { m } {}
Proxy(Proxy&& rhs) : m_ { rhs.m_ }, a { std::move(rhs.a) }, index{rhs.index} {} // 1

Proxy operator[](int i)
{
++index;

return { std::move(*this) };
}

Proxy& operator=(int value)
{
m_.v = value;

return *this;
}

Matrix& m_;
int     index = 0;

std::array a;
};

Proxy operator[](int index)
{
return { *this };
}

int v = -1;
};

int main()
{
Matrix      m;
const auto& q = m[1][2][3]; // 2
std::cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/79057717/do-moving-a-member-and-prolongation-of-lifetime-guaranteed-in-my-case[/url]

Вернуться в «C++»