Namespaces
Variants
Views
Actions

std::{{{1}}}::empty

From cppreference.com
Revision as of 10:15, 2 August 2012 by P12 (Talk | contribs)

bool empty() const;

Checks if the container has no elements, i.e. whether begin() == end().

Contents

Parameters

(none)

Return value

true if the container is empty, false otherwise

Exceptions

noexcept specification:  
noexcept
  

Complexity

Constant

Example

The following code uses empty to check if a std::{{{1}}}<int> contains any elements:

#include <{{{1}}}>
#include <iostream>
 
int main()
{
    std::{{{1}}}<int> numbers;
    std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';
 
    numbers.push_back(42);
    numbers.push_back(13317); 
    std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}

Output:

Initially, numbers.empty(): 1
After adding elements, numbers.empty(): 0

See also

Template:cpp/container/dcl list size