You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And then imagine we need to make a copy of that vector:
auto v2 = std::vector{v.begin(), v.end()};
Are you expecting v2 to be a vector of 4 integers? Surprise :) This is a std::vector<std::vector<int>::iterator> with 2 iterators.
The way to fix that copying:
auto v2 = std::vector(v.begin(), v.end());
Note that it's easy to reach that typo due to code styles which are forcing programmers to always use auto and always prefer braced initialization.
You may suggest to change copying to auto v2 = v;, that's correct but not always possible - imagine we are copying subarray.
The text was updated successfully, but these errors were encountered:
Assume we have a vector of 4 integers:
And then imagine we need to make a copy of that vector:
Are you expecting
v2
to be a vector of 4 integers? Surprise :) This is astd::vector<std::vector<int>::iterator>
with 2 iterators.The way to fix that copying:
Note that it's easy to reach that typo due to code styles which are forcing programmers to always use auto and always prefer braced initialization.
You may suggest to change copying to
auto v2 = v;
, that's correct but not always possible - imagine we are copying subarray.The text was updated successfully, but these errors were encountered: