The unordered_set::reserve() method is a builtin function in C++ STL which is used to request capacity change of unordered_set. It sets the number of buckets in the container to contain at least n elements. If n is greater than the current bucket_count multiplied by the max_load_factor, the container’s bucket_count is increased and a rehash is forced. If n is lower than the bucket_count, then the function has no effect on it.
Parameter: The function accepts a single mandatory parameter n which sets the number of buckets in the container (bucket_count) to the most appropriate to contain at least n elements.
Return Value: This function doesn’t returns anything.
Below programs illustrate the unordered_set::reserve() function:
geeksforgeeks users geeks for
- unordered_multimap reserve() function in C++ STL
- unordered_map reserve() in C++ STL
- Using std::vector::reserve whenever possible
- unordered_multiset reserve() in C++ STL
- Function Overloading vs Function Overriding in C++
- How to call some function before main() function in C++?
- What happens when a virtual function is called inside a non-virtual function in C++
- Difference between Virtual function and Pure virtual function in C++
- fma() function in C++
- log() function in C++
- exp() function C++
- div() function in C++
- map key_comp() function in C++ STL
- valarray log() function in C++
- valarray pow() function in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.