I've recently started upgrading my current projects from VS2015 to VS2019 and VS2019 is a lot more restrictive about some things. One thing I have an issue with in particular is the way I'm currently releasing the memory of vectors:
std::vector<int> v(10);
v.swap(std::vector<int>()); // v should now be empty with no memory held
This worked fine in VS2015 but in VS2019 it no longer works because the vector I swap with is constant and vector::swap()
requires a reference. This behavior has changed recently and must be a problem for more people than me given that this is the recommended way of releasing the memory of a vector. MS docs on the issue: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2664?view=msvc-160
What is the new recommended way of releasing the memory of a vector if you can't swap it away?