Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit 361d7bc

Browse files
Refine reserve() documentation for unordered_set
Updated the description and notes for the reserve() function in std::unordered_set. Added details about return value and clarified usage.
1 parent 71f7c86 commit 361d7bc

File tree

1 file changed

+14
-11
lines changed
  • content/cpp/concepts/unordered-set/terms/reserve

1 file changed

+14
-11
lines changed

content/cpp/concepts/unordered-set/terms/reserve/reserve.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
Title: 'reserve()'
3-
Description: 'Requests capacity change for std::unordered_set so it can accommodate at least n elements without exceeding the maximum load factor.'
3+
Description: 'Requests capacity change for `std::unordered_set` so it can accommodate at least n elements without exceeding the maximum load factor.'
44
Subjects:
55
- 'Code Foundations'
66
- 'Computer Science'
77
Tags:
8-
- 'Iterators'
8+
- 'Containers'
99
- 'Sets'
1010
- 'STL'
11-
- 'Algorithms'
1211
CatalogContent:
1312
- 'learn-c-plus-plus'
1413
- 'paths/computer-science'
@@ -28,14 +27,7 @@ unordered_set_name.reserve(n);
2827

2928
**Return value:**
3029

31-
- `void`
32-
33-
**Notes:**
34-
35-
- Effectively calls `rehash(ceil(n / max_load_factor()))`.
36-
- May invalidate iterators if a rehash occurs; references and pointers to elements remain valid.
37-
- Use `rehash(k)` to set the bucket count directly; use `reserve(n)` to plan for element count.
38-
- Does not impose ordering; iteration order remains implementation-defined.
30+
This method doesn't return anything (`void`).
3931

4032
## Example
4133

@@ -68,6 +60,17 @@ int main() {
6860
}
6961
```
7062

63+
The output of this code is:
64+
65+
```shell
66+
Buckets before: 3
67+
Buckets after: 11
68+
Max load factor: 1
69+
Load factor: 0.272727
70+
Size: 7
71+
Buckets final: 11
72+
```
73+
7174
## Codebyte Example
7275

7376
This example demonstrates `reserve()` with strings, and prints capacity-related information:

0 commit comments

Comments
 (0)