Returns the vector <vector <int>> from a function that calls any move constructors in C ++ 11
Does C ++ 11 return vector<vector<int> >from a function that calls any move constructors? Or will the code below make another copy of all the vectors and their elements?
vector< vector<int> > Func() {
vector< vector<int> > vec;
//vec is filled here
return vec;
}
For stl containers of simple types, is there anything in common to determine when a move constructor is used or when copying is performed when returning them as values from functions?
+4
1 answer
Operators
returnspecially covered by the standard, which is automatically treated as movement. So yes, this will call the move constructor.
- ++ 11, [class.copy]§31+32:
31 , / ... /, , ( ):
- return , ( catch-clause) cvunqualified , , / ,
- ...
32. , , , lvalue, , , , rvalue. rvalue (, cv-qualit), , lvalue....
( )
, , , , .
(, @BjornPollex, , )
+3