Skip to content

Commit 372f5e1

Browse files
committed
fixup! fixup! docs: add ranged based for loop concept files
1 parent f5ab895 commit 372f5e1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

concepts/ranged-loops/introduction.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ for (const std::string part : file_name) {
5050
// Output: JIF
5151
```
5252

53-
This prevents accidental modification of `number` but will still make a copy with every side-effect from above.
53+
This prevents accidental modification of `part` but will still make a copy with every side-effect from above.
5454

5555
## Using References to Modify Elements
5656

@@ -69,7 +69,13 @@ for (std::string& member : trilobites) {
6969
// trilobites now contains "Johnny Ramone", "Joey Ramone", "Dee Dee Ramone", "CJ Ramone"};
7070
```
7171

72-
If it is not necessary to change the container content it is advisable to use a `const` reference, which can be further optimized by the compiler.
72+
~~~~exercism/note
73+
If you don't change your loop variable, it is advisable to use `const` references.
74+
Copy operations can significantly slow your algorithms for larger data structures.
75+
The only exception for this rule are [fundamental types][fundamentals] like `int`, `char`, and `long`, as the reference process has more overhead than a simple copy.
76+
77+
[fudnamentals]: https://en.cppreference.com/w/cpp/language/types
78+
~~~~
7379

7480
## When to Use Range-Based Loops
7581

0 commit comments

Comments
 (0)