For container, Call empty() instead of of checking size() against zero.
it’s very easy to understand it.
for vector, size(), capacity() and max_size() can be seen below: capacity is
equal or bigger than size. So if you want to avoid allocate the unnecessary
space. LLVM give a SmallVecotr<type, N> example, you can use N to
specify a smaller vector to avoid waste.
You want to avoid allocation, 1), if you know the number, then use reserve,
2) if you don’t know the number, you can reserve maximum space, then you
can trim off any excess capaciy. you can use shrink_to_fit() function too.
Just remember string(s).swap(s)