From dd4a6c3b7106ef14482d641b14d70633e3c0904e Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 7 Mar 2014 17:23:29 +0000 Subject: [PATCH] C++11: Copy pointers with const auto * llvm-svn: 203254 --- docs/CodingStandards.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CodingStandards.rst b/docs/CodingStandards.rst index a762bf358e3..f9685d69ad5 100644 --- a/docs/CodingStandards.rst +++ b/docs/CodingStandards.rst @@ -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 ============