Home > Enterprise >  There is a list whose contents are type of vector<T>
There is a list whose contents are type of vector<T>

Time:11-12

What should I do to get any vector of the list?

I use following code to do it currently:

list<vector<T>> alist;

list<vector<T>>::iterator iter = alist.begin();

vector<T> vec(*iter);

is there any other way by which I don't need to copy the data?

CodePudding user response:

What you have can be written equivalently as:

vector<T> vec = alist.front();

CodePudding user response:

If you need to access all vector of list and modify individual values, you can write as descried below.

    for (auto& v : alist) {
        for (auto& i : v) {
            i = 13;
        }
    }
  • Related