Skip to content

vector_pro::capacity

C++
size_type capacity() const noexcept;

Return size of allocated storage capacity

Returns the size of the storage space currently allocated for the vector, expressed in terms of elements.

Notice that this capacity does not suppose a limit on the size of the vector. The theoretical limit on the size of a vector is given by member max_size.

Parameters

none

Return value

The size of the currently allocated storage capacity in the vector, measured in terms of the number elements it can hold.

Example

C++
// comparing size, capacity and max_size
#include <iostream>
#include "vector_pro.h"

/**
 * Output:
 * size: 100
 * capacity: 128
 * max_size: 9223372036854775807
 */


int main ()
{
  vector_pro<int> myvector;

  // set some content in the vector:
  for (int i=0; i<100; i++) myvector.push_back(i);

  std::cout << "size: " << (int) myvector.size() << '\n';
  std::cout << "capacity: " << (int) myvector.capacity() << '\n';
  std::cout << "max_size: " << (std::size_t) myvector.max_size() << '\n';
  return 0;
}

Complexity

Constant.