[llvm] r203257 - C++11: Remove const from in auto guidelines
Duncan P. N. Exon Smith
dexonsmith at apple.com
Fri Mar 7 10:06:15 PST 2014
Author: dexonsmith
Date: Fri Mar 7 12:06:15 2014
New Revision: 203257
URL: http://llvm.org/viewvc/llvm-project?rev=203257&view=rev
Log:
C++11: Remove const from in auto guidelines
Using const is orthogonal to guidelines on using auto& and auto*.
Modified:
llvm/trunk/docs/CodingStandards.rst
Modified: llvm/trunk/docs/CodingStandards.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CodingStandards.rst?rev=203257&r1=203256&r2=203257&view=diff
==============================================================================
--- llvm/trunk/docs/CodingStandards.rst (original)
+++ llvm/trunk/docs/CodingStandards.rst Fri Mar 7 12:06:15 2014
@@ -746,23 +746,21 @@ The convenience of ``auto`` makes it eas
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, and use ``const auto *`` when copying pointers.
+As a rule of thumb, use ``auto &`` unless you need to copy the result, and use
+``auto *`` when copying pointers.
.. code-block:: c++
- // Typically there's no reason to mutate or modify Val.
+ // Typically there's no reason to copy.
for (const auto &Val : Container) { observe(Val); }
-
- // Remove the const if you need to modify Val.
for (auto &Val : Container) { Val.change(); }
// 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(); }
+ for (const auto *Ptr : Container) { observe(*Ptr); }
+ for (auto *Ptr : Container) { Ptr->change(); }
Style Issues
============
More information about the llvm-commits
mailing list