std::hive<T,Allocator>::capacity
Von de.cppreference.net
size_type capacity() const noexcept;
|
||
Gibt die Anzahl der Elemente zurück, die der Hive aufnehmen kann, ohne eine Neubelegung weiterer Elementblöcke zu erfordern.
Rückgabewert
Kapazität des derzeit zugewiesenen Speichers.
Komplexität
Konstant.
Beispiel
Diesen Code ausführen
#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';
}
Mögliche Ausgabe:
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
Siehe auch
| gibt die Anzahl der Elemente zurück (öffentliche Memberfunktion) | |
| reserviert Speicher (öffentliche Memberfunktion) |