I read a lot of questions here about how to completely clear the line (for example, reset the capacity, free the memory). My question, although it is the exact opposite; Is there any reliable way to discard a string (length) while still guaranteeing its capacity?
Example: reusing a timeline in a loop.
This will probably happen by default if I do something like
str.clear() str.reserve(256)
in each iteration of the loop, at least when using Visual Studio according to the answer to this post: Concrete behavior of std :: string in visual studio?
But relying on the "probable" seems a bit risky.
source share