[llvm] r203254 - C++11: Copy pointers with const auto *

David Blaikie dblaikie at gmail.com
Fri Mar 7 09:39:13 PST 2014


On Fri, Mar 7, 2014 at 9:23 AM, Duncan P. N. Exon Smith
<dexonsmith at apple.com> wrote:
> Author: dexonsmith
> Date: Fri Mar  7 11:23:29 2014
> New Revision: 203254
>
> URL: http://llvm.org/viewvc/llvm-project?rev=203254&view=rev
> Log:
> C++11: Copy pointers with const 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=203254&r1=203253&r2=203254&view=diff
> ==============================================================================
> --- llvm/trunk/docs/CodingStandards.rst (original)
> +++ llvm/trunk/docs/CodingStandards.rst Fri Mar  7 11:23:29 2014
> @@ -747,7 +747,7 @@ is a copy.  Particularly in range-based
>  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.

Drop the "const" here (since it's not necessary - it depends if you
want a pointer to non-const or a pointer to const - as you
demonstrate, both being acceptable, below)

>
>  .. 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
>  ============
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list