empty

Syntax:

    #include <deque>
    bool empty() const;

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

For example, the following code uses empty() as the stopping condition on a while loop to clear a deque and display its contents in reverse order:

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

Related Topics: size