mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
C++11: Copy pointers with const auto *
llvm-svn: 203254
This commit is contained in:
parent
a9db25cef0
commit
dd4a6c3b71
@ -747,7 +747,7 @@ is a copy. Particularly in range-based ``for`` loops, careless copies are
|
||||
expensive.
|
||||
|
||||
As a rule of thumb, use ``const auto &`` unless you need to mutate or copy the
|
||||
result.
|
||||
result, and use ``const auto *`` when copying pointers.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
@ -760,6 +760,10 @@ result.
|
||||
// Remove the reference if you really want a new copy.
|
||||
for (auto Val : Container) { Val.change(); saveSomewhere(Val); }
|
||||
|
||||
// Copy pointers, but make it clear that they're pointers.
|
||||
for (const auto *Val : Container) { observe(*Val); }
|
||||
for (auto *Val : Container) { Val->change(); }
|
||||
|
||||
Style Issues
|
||||
============
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user