File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 20
20
* [ Ownership and Smart Pointers] ( #ownership-and-smart-pointers )
21
21
* [ Others] ( #others )
22
22
* [ Type casting] ( #type-casting )
23
+ * [ Using ` auto ` ] ( #using-auto )
23
24
* [ Do not include ` *.h ` if ` *-inl.h ` has already been included] ( #do-not-include-h-if--inlh-has-already-been-included )
24
25
* [ Avoid throwing JavaScript errors in C++ methods] ( #avoid-throwing-javascript-errors-in-c )
25
26
* [ Avoid throwing JavaScript errors in nested C++ methods] ( #avoid-throwing-javascript-errors-in-nested-c-methods )
@@ -209,6 +210,24 @@ Never use `std::auto_ptr`. Instead, use `std::unique_ptr`.
209
210
- Use `static_cast` for casting whenever it works
210
211
- `reinterpret_cast` is okay if `static_cast` is not appropriate
211
212
213
+ ### Using `auto`
214
+
215
+ Being explicit about types is usually preferred over using `auto`.
216
+
217
+ Use `auto` to avoid type names that are noisy, obvious, or unimportant. When
218
+ doing so, keep in mind that explicit types often help with readability and
219
+ verifying the correctness of code.
220
+
221
+ ```cpp
222
+ for (const auto& item : some_map) {
223
+ const KeyType& key = item.first;
224
+ const ValType& value = item.second;
225
+ // The rest of the loop can now just refer to key and value,
226
+ // a reader can see the types in question, and we've avoided
227
+ // the too-common case of extra copies in this iteration.
228
+ }
229
+ ```
230
+
212
231
### Do not include ` *.h ` if ` *-inl.h ` has already been included
213
232
214
233
Do
You can’t perform that action at this time.
0 commit comments