empty [C++ Reference]
Keywords: stl,set,empty
Date: 2008-10-14T15:42:07-0700

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

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

## empty

Syntax:

        #include <set>
        bool empty() const;

The empty() function returns true if the set has no elements, false otherwise.

For example, the following code uses empty() to determine if a set is empty:

         // Create a set of characters
         set<char> charSet;
         cout << (charSet.empty() ? "EMPTY " : "NON-EMPTY ");
         charSet.insert( 'A' );
         charSet.insert( 'B' );
         charSet.insert( 'C' );
         cout << (charSet.empty() ? "EMPTY " : "NON-EMPTY ");
         charSet.clear();
         cout << (charSet.empty() ? "EMPTY " : "NON-EMPTY ");
         // output is "EMPTY NON-EMPTY EMPTY "

Related Topics: size

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