The reserve() function of unordered_multiset sets the number of buckets in the container (bucket_count) to the most appropriate 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 that, the function may have no effect.
void reserve( size_type n );
where size_type is an unsigned integral type.
Parameters: This method accepts a mandatory parameter n which is the number of elements requested as minimum capacity.
Returns: It does not returns any value.
Below are the programs to illustrate reserve() method:
The values in unordered_multiset : 7 6 5
The values in unordered_multiset : GeeksforGeeks forGeeks Geeks
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Using std::vector::reserve whenever possible
- unordered_map reserve() in C++ STL
- unordered_multimap reserve() function in C++ STL
- unordered_set reserve() function in C++ STL
- How to iterate over the elements of an std::tuple in C++
- How to stream large .mp4 files?
- How to add a custom styled Toast in Android using Kotlin
- Android WebView in Kotlin
- Delegated Properties in Kotlin
- Android Rotate animations in Kotlin
- What is the difference between created and mounted event in VueJS?
- How to add a PHP page to WordPress?
- How to get button toggle state within HTML?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : verma98