std::unordered_set<Key,Hash,KeyEqual,Allocator>::max_bucket_count - cppreference.com

From cppreference.com

size_typemax_bucket_count()const;(since C++11)Returns the maximum number of buckets the container is able to hold due to system or library implementation limitations.

Parameters

(none)

Return value

Maximum number of buckets.

Complexity

Constant.

Example

Run this code

#include<iostream>#include<unordered_set>intmain(){structHa{std::size_toperator()(longx)const{returnstd::hash<long>{}(x);};};autoc1=std::unordered_set<char>{};autoc2=std::unordered_set<long>{};autoc3=std::unordered_set<long,std::hash<int>>{};autoc4=std::unordered_set<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';}Possible output:

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