<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[To move or not to move]]></title><description><![CDATA[<pre><code>vector&lt;string&gt; stuff;
{
	string s = getStuff();
	if (s.size())
		stuff.push_back(move(s));
}
</code></pre>
<p>Sollte ich hier das move weglassen, weil der Compiler <em>s</em> selbst als Temporary erkennt?<br />
Es hieß mal irgendwo, dass</p>
<pre><code>return move(value);
</code></pre>
<p>ineffizienter als</p>
<pre><code>return value;
</code></pre>
<p>bei lokalen Variablen ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319983/to-move-or-not-to-move</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 16:03:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319983.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Sep 2013 12:20:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to To move or not to move on Wed, 11 Sep 2013 12:20:00 GMT]]></title><description><![CDATA[<pre><code>vector&lt;string&gt; stuff;
{
	string s = getStuff();
	if (s.size())
		stuff.push_back(move(s));
}
</code></pre>
<p>Sollte ich hier das move weglassen, weil der Compiler <em>s</em> selbst als Temporary erkennt?<br />
Es hieß mal irgendwo, dass</p>
<pre><code>return move(value);
</code></pre>
<p>ineffizienter als</p>
<pre><code>return value;
</code></pre>
<p>bei lokalen Variablen ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351826</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351826</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Wed, 11 Sep 2013 12:20:00 GMT</pubDate></item><item><title><![CDATA[Reply to To move or not to move on Wed, 11 Sep 2013 12:27:10 GMT]]></title><description><![CDATA[<p>In deinem Beispielcode steht kein return. Warum sollte dein &quot;es hiess mal&quot; also dort greifen. Desweiteren sollte std::move nur den Typ umwandeln, d.h. es ist eine nop und sorgt nur dafuer, dass die &quot;richtige&quot; ueberladung ausgewaehlt wird. Keine Ahnung, ob es unter <a href="http://channel9.msdn.com/Events/GoingNative/2013/Don-t-Help-the-Compiler" rel="nofollow">http://channel9.msdn.com/Events/GoingNative/2013/Don-t-Help-the-Compiler</a> faellt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351828</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 11 Sep 2013 12:27:10 GMT</pubDate></item><item><title><![CDATA[Reply to To move or not to move on Wed, 11 Sep 2013 12:53:26 GMT]]></title><description><![CDATA[<p>nwp3 schrieb:</p>
<blockquote>
<p>Sollte ich hier das move weglassen, weil der Compiler <em>s</em> selbst als Temporary erkennt?</p>
</blockquote>
<p>Selbst wenn der Compiler so schlau sein sollte, dass er das erkennt, darf er hier kein move automatisch verwenden -- zumindest nicht in einer &quot;as-if&quot;-Regel-verletzenden Weise. Deine Verwendung von std::move ist hier also genau richtig und vordbildlich.</p>
<p>Die einzige Stelle, bei der ein Compiler ein Lvalue als Rvalue behandeln darf, ist beim <code>return</code> eines funktionslokalen Objekts.</p>
<p>nwp3 schrieb:</p>
<blockquote>
<p>Es hieß mal irgendwo, dass</p>
<pre><code>return move(value);
</code></pre>
<p>ineffizienter als</p>
<pre><code>return value;
</code></pre>
<p>bei lokalen Variablen ist.</p>
</blockquote>
<p>Genau. Du hebelst nämlich durch diese Verwendung von <code>move</code> die NRVO-Optimierung aus, die ein Compiler hier sonst anwenden dürfte (und typischerweise auch tut). NRVO ist noch günstiger als eine Move-Konstruktion. Mit std::move würdest du hier mindestens eine Move-Konstruktion bekommen, weil die Copy-Elision-Regel nicht mehr greifen kann. Das liegt daran, dass std::move etwas mehr als ein Cast ist: Es ist ein Funktionsaufruf -- auch wenn dieser geinlined werden kann und die Funktion sonst nichts besonderes macht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351835</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351835</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 11 Sep 2013 12:53:26 GMT</pubDate></item><item><title><![CDATA[Reply to To move or not to move on Wed, 11 Sep 2013 12:47:36 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>...</p>
</blockquote>
<p>Vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351837</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351837</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Wed, 11 Sep 2013 12:47:36 GMT</pubDate></item><item><title><![CDATA[Reply to To move or not to move on Wed, 11 Sep 2013 13:29:47 GMT]]></title><description><![CDATA[<p>siehe auch <a href="http://stackoverflow.com/questions/4303513/push-back-vs-emplace-back" rel="nofollow">http://stackoverflow.com/questions/4303513/push-back-vs-emplace-back</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351847</guid><dc:creator><![CDATA[dd++ 0]]></dc:creator><pubDate>Wed, 11 Sep 2013 13:29:47 GMT</pubDate></item></channel></rss>