array::empty

array::empty

 

Tests whether no elements are present.

constexpr bool empty() const;

The member function returns true only if N == 0.

Example

 

// std_tr1__array__array_empty.cpp 
// compile with: /EHsc 
#include <array> 
#include <iostream> 

typedef std::array<int, 4> Myarray; 
int main() 
    { 
    Myarray c0 = {0, 1, 2, 3}; 

// display contents " 0 1 2 3" 
    for (Myarray::const_iterator it = c0.begin(); 
        it != c0.end(); ++it) 
        std::cout << " " << *it; 
    std::cout << std::endl; 

// display whether c0 is empty " false" 
    std::cout << std::boolalpha << " " << c0.empty(); 
    std::cout << std::endl; 

    std::array<int, 0> c1; 

// display whether c1 is empty " true" 
    std::cout << std::boolalpha << " " << c1.empty(); 
    std::cout << std::endl; 

    return (0); 
    } 

0 1 2 3
false
true

Requirements

Header: <array>

Namespace: std

Show:
© 2016 Microsoft