Skip to content

Commit d8ea5ad

Browse files
committed
Update notes on return types
1 parent 5e2eead commit d8ea5ad

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

04-Considering_Safety.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ public:
2424

2525
```
2626

27-
### Consider Return By Value for Mutable Data, `const &` for Immutable
27+
### Carefully Consider Your Return Types
2828

29-
You don't want to have to pay a cost for copying the data when you don't need to, but you also don't want to have to safely return data in a threading scenario.
29+
* Getters
30+
* Returning by `&` or `const &` can have significant performance savings when the normal use of the returned value is for observation
31+
* Returning by value is better for thread safety and if the normal use of the returned value is to make a copy anyhow, there's no performance lost
32+
* If your API uses covariant return types, you must return by `&` or `*`
33+
* Temporaries and local values
34+
* Always return by value.
3035

31-
See also this discussion for more information: https://github.com/lefticus/cppbestpractices/issues/21
36+
37+
references: https://github.com/lefticus/cppbestpractices/issues/21 https://twitter.com/lefticus/status/635943577328095232
3238

3339
### Do not pass and return simple types by const ref
3440

0 commit comments

Comments
 (0)