empty [C++ Reference]
Keywords: stl,list,empty
Date: 2009-07-24T13:27:59-0700

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

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

## empty

Syntax:

        #include <list>
        bool empty() const;

The empty() function returns true if the list has no elements, false otherwise. For example, the following code uses empty() as the stopping condition on a while loop to clear a list and display its contents in reverse order:

       list<int> v;
       for( int i = 0; i < 5; i++ ) {
         v.push_back(i);
       }
       while( !v.empty() ) {
         cout << v.back() << endl;
         v.pop_back();
       }

Related Topics: size

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