Skip to content

vector_pro::empty

C++
bool empty() const noexcept;

Test whether the container is empty

Returns whether the vector is empty (i.e. whether its size is 0).

Parameters

none

Return value

true if the container size is 0, false otherwise.

Example

C++
// vector_pro::empty
#include <iostream>
#include "vector_pro.h"

/**
 * Output:
 * total: 55
 */

int main ()
{
  vector_pro<int> myvector;
  int sum (0);

  for (int i=1;i<=10;i++) myvector.push_back(i);

  while (!myvector.empty())
  {
     sum += myvector.back();
     myvector.pop_back();
  }

  std::cout << "total: " << sum << '\n';

  return 0;
}

Complexity

Constant.