clear [C++ Reference]
Keywords: stl,multiset,clear
Date: 2009-09-16T06:27:47-0700

[[clear]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## clear

Syntax:

        #include <set>
        void clear();

The function clear() deletes all of the elements in the multiset. This will call the destructor for all of the elements in the multiset. clear() runs in linear time.

After a call to clear, the multiset's new size will be zero. The multiset's capacity however, will not be changed, and the multiset will not release its allocated memory.

If you want to empty a multiset of all of its elements, as well as its capacity, then you can use the swap trick:

        std:: multiset aMultiset;
        //[...]
        aMultiset.swap( std::multiset() );

This will create a new temporary empty multiset, which will swap with the multiset you wish to empty.

Related Topics: erase, swap

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •