
enerally, STL containers handle their storage automatically and efficiently. Yet, there are cases when you need to regulate a container's storage manuallyfor example when you want to trim or empty it. This article shares two simple and effective techniques to accomplish these tasks.

How do you trim a container whose capacity is larger than necessary? How do you force a container to destroy its elements and set its capacity to 0?

Use the self-swapping idioms.