Avoid const locals that are returned? : <p>I always thought that it's good to have const locals be const</p>

<pre><code>void f() {
    const resource_ptr p = get();
    // ...
}
</code></pre>

<p>However last week I watched students that worked on a C++ exercise and that wondered about a const pointer being returned</p>

<pre><code>resource_ptr f() {
    const resource_ptr p = get();
    // ...
    return p;
}
</code></pre>

<p>Here, if the compiler can't apply NRVO (imagine some scenario under which that is true, perhaps returning one of two pointers, depending on a condition), suddenly the <code>const</code> becomes a pessimization because the compiler can't move from <code>p</code>, because it's const. </p>

<p>Is it a good idea to try and avoid <code>const</code> on returned locals, or is there a better way to deal with this?</p>
