Namespaces
Variants

std::hive<T,Allocator>::capacity

From cppreference.com
 
 
 
 
size_type capacity() const noexcept;

Returns the number of elements that the hive can hold without requiring reallocation of more element blocks.

Return value

Capacity of the currently allocated storage.

Complexity

Constant.

Example

#include <iomanip>
#include <iostream>
#include <hive>

int main()
{
    int sz = 1000;
    std::hive<int> v;

    auto cap = v.capacity();
    std::cout << "Initial size: " << v.size() << ", capacity: " << cap << '\n';

    std::cout << "\nDemonstrate the capacity's growth policy."
                 "\nSize:  Capacity:  Ratio:\n" << std::left;
    while (sz-- > 0)
    {
        v.insert(sz);
        if (cap != v.capacity())
        {
            std::cout << std::setw( 7) << v.size()
                      << std::setw(11) << v.capacity()
                      << std::setw(10) << v.capacity() / static_cast<float>(cap) << '\n';
            cap = v.capacity();
        }
    }

    std::cout << "\nFinal size: " << v.size() << ", capacity: " << v.capacity() << '\n';
}

Possible output:

Initial size: 0, capacity: 0

Demonstrate the capacity's growth policy.
Size:  Capacity:  Ratio:
1      76         inf       
77     152        2         
153    304        2         
305    559        1.83882   
560    814        1.45617   
815    1069       1.31327   

Final size: 1000, capacity: 1069

See also

returns the number of elements
(public member function) [edit]
reserves storage
(public member function) [edit]