You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 04-Considering_Safety.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,11 +24,17 @@ public:
24
24
25
25
```
26
26
27
-
### Consider Return By Value for Mutable Data, `const &` for Immutable
27
+
### Carefully Consider Your Return Types
28
28
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.
30
35
31
-
See also this discussion for more information: https://github.com/lefticus/cppbestpractices/issues/21
0 commit comments