Namespaces
Variants

std::unordered_map<Key,T,Hash,KeyEqual,Allocator>:: max_bucket_count

From cppreference.net

size_type max_bucket_count ( ) const ;
(depuis C++11)

Retourne le nombre maximal de compartiments que le conteneur peut contenir en raison des limitations du système ou de l'implémentation de la bibliothèque.

Table des matières

Paramètres

(aucun)

Valeur de retour

Nombre maximum de compartiments.

Complexité

Constante.

Exemple

#include <iostream>
#include <unordered_map>
int main()
{
    struct Ha { std::size_t operator()(long x) const { return std::hash<long>{}(x); }; };
    auto c1 = std::unordered_map<char, long>{};
    auto c2 = std::unordered_map<long, long>{};
    auto c3 = std::unordered_map<long, long, std::hash<int>>{};
    auto c4 = std::unordered_map<long, long, Ha>{};
    std::cout
        << "Max bucket count of\n" << std::hex << std::showbase
        << "c1: " << c1.max_bucket_count() << '\n'
        << "c2: " << c2.max_bucket_count() << '\n'
        << "c3: " << c3.max_bucket_count() << '\n'
        << "c4: " << c4.max_bucket_count() << '\n'
        ;
}

Sortie possible :

Max bucket count of
c1: 0xfffffffffffffff
c2: 0xfffffffffffffff
c3: 0xfffffffffffffff
c4: 0xaaaaaaaaaaaaaaa

Voir aussi

renvoie le nombre de compartiments
(fonction membre publique)