diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-07 18:06:15 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-07 18:06:15 +0000 |
commit | feed88059f2ad150865b037c91aa0246ebcc8f76 (patch) | |
tree | d0be46fed44f8504c5ca7e24b08e401d1bbb4ddd /docs | |
parent | f7952d3a5f294b2c4a9e59e06edc927fddf37e78 (diff) | |
download | llvm-feed88059f2ad150865b037c91aa0246ebcc8f76.tar.gz |
C++11: Remove const from in auto guidelines
Using const is orthogonal to guidelines on using auto& and auto*.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203257 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r-- | docs/CodingStandards.rst | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/docs/CodingStandards.rst b/docs/CodingStandards.rst index f9685d69ad5d..2ebdfbc91bf6 100644 --- a/docs/CodingStandards.rst +++ b/docs/CodingStandards.rst @@ -746,23 +746,21 @@ The convenience of ``auto`` makes it easy to forget that its default behavior 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 ============ |