つまりはこういうことですか?
C#
1using System;
2using System.Collections.Generic;
3public class Test {
4 public static void Main() {
5 var x = new List<List<int>> {new List<int> {0, 1, 2}};
6 var a = x[0];
7 var y = x;
8 x = null;
9 Console.WriteLine(y[0][0]);
10 ++a[0];
11 Console.WriteLine(y[0][0]);
12 }
13}
x = null;
が駄目ということは、y
に写す以前にx
経由で中身を参照している場合、その参照を通して変更されることを防ぎたいのだと思います。上のコードでは、y[0][0]
の値は変わってしまいます。
残念ながら、C++のムーブセマンティクスも同じ動きです。
C++
1#include <iostream>
2#include <vector>
3#include <utility>
4using namespace std;
5int main(void){
6 vector<vector<int>> x = {{0, 1, 2}};
7 auto &a = x[0];
8 auto y = move(x);
9 cout << y[0][0] << endl;
10 ++a[0];
11 cout << y[0][0] << endl;
12}
以前の参照を通してy[0][0]
の値は同様に変更されます。C++の場合は値型なので細かいところは違うのですが、変更を完全に防ぎたい場合は深いコピーをする以外方法はないと思います。