質問

I have a map<int, vector<int>> M. In some functions I want to use M[someInt] multiple times. Instead of having M[someInt].size(), M[someInt].push_back(123) etc all over the place I want to use a local variable instead.

I'm currently using vector<int> v = M[someInt]; however I don't want to copy the contents of the vector. I think I can do vector<int> *v = &M[someInt];

How can I create a local variable that refers to M[someInt] w/o copying the vector's contents and, ideally, w/o using a pointer?

役に立ちましたか?

解決

Do vector<int>& v = M[someInt];.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top