C++11: Copy pointers with const auto *

llvm-svn: 203254
This commit is contained in:
Duncan P. N. Exon Smith 2014-03-07 17:23:29 +00:00
parent 0990e05d43
commit 6b3d6a4fe9
1 changed files with 5 additions and 1 deletions

View File

@ -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
============