File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 2020 * [ Ownership and Smart Pointers] ( #ownership-and-smart-pointers )
2121* [ Others] ( #others )
2222 * [ Type casting] ( #type-casting )
23+ * [ Using ` auto ` ] ( #using-auto )
2324 * [ Do not include ` *.h ` if ` *-inl.h ` has already been included] ( #do-not-include-h-if--inlh-has-already-been-included )
2425 * [ Avoid throwing JavaScript errors in C++ methods] ( #avoid-throwing-javascript-errors-in-c )
2526 * [ 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`.
209210- Use `static_cast` for casting whenever it works
210211- `reinterpret_cast` is okay if `static_cast` is not appropriate
211212
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+
212231### Do not include ` *.h ` if ` *-inl.h ` has already been included
213232
214233Do
You can’t perform that action at this time.
0 commit comments