0

I want to create a multi-dimensional array, let's say m x n Can I accomplish something like that using the fill constructor of a vector?

For example:

vector<vector<int>> foo(n, vector<int>(m));

The closest thing I saw addressing this on StackOverflow was: How do I declare and initialize a 2d int vector in C++? But it looked like there was still some question of whether it was legal.

I am using Visual Studio 2013 and it seems to work fine.

EDIT:

I'm also going to guess here that this creates a temporary vector of size m copies it n times and then destroys it. Will the compiler optimize out that temporary construction? I'm hoping the answer to that is yes, cause using a move here seems like it wouldn't accomplish what I hope either.

Community
  • 1
  • 1
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288

0 Answers0