Meaning of .clear() for containers

Jesse Phillips jessekphillips+D at gmail.com
Tue Jan 4 08:53:59 PST 2011


Answering a question over on stack overflow I realized that clear() has 2 meanings.

TDPL says that clear should be used to free resources of the object and place the object into an invalid state. That is failure can occur but memory corruption is prevent, similar to null for pointer types.

However for container types clear() is used to empty the container. It is still valid to use the container after calling clear(), but the definition from TDPL suggest that this can not be expected.


More information about the Digitalmars-d mailing list