<?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[const von const std::list wegcasten]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich hab eine &quot;Interface&quot;-Methode wo mir eine const std::list übergeben wird. Ich hab keine Chance, den Typen zu ändern, muss jetzt aber aus Performance gründen die Liste sortieren wenn sie mehr als xxx Elemente enthält.</p>
<p>Dafür hab ich mir auch schon einen Comparator geschrieben:</p>
<pre><code class="language-cpp">bool compare(std::pair&lt;std::string, double&gt; &amp;first, 
			 std::pair&lt;std::string, double&gt; &amp;second)
{
	return ( first.first.compare( second.first ) &lt;= 0) ? true : false;
}
</code></pre>
<p>Leider muss ich momentan, eben weil die Referenz const ist, eine neue std::list anlegen, wo die alte reinkopiert wird, und erst bei dieser kann ich dann .sort() aufrufen was nicht gerade effizient ist.</p>
<p>Ich bin mir darüber im klaren das das schlechte Stil ist und das das gefährlich ist, wenn man nicht weiß wer die Liste noch braucht. Aber ich weiß was ich tue <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Welche Möglichkeiten habe ich bzw. wie kann ich das const &quot;wegcasten&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/218735/const-von-const-std-list-wegcasten</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 22:13:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/218735.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 24 Jul 2008 13:45:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to const von const std::list wegcasten on Thu, 24 Jul 2008 13:45:24 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich hab eine &quot;Interface&quot;-Methode wo mir eine const std::list übergeben wird. Ich hab keine Chance, den Typen zu ändern, muss jetzt aber aus Performance gründen die Liste sortieren wenn sie mehr als xxx Elemente enthält.</p>
<p>Dafür hab ich mir auch schon einen Comparator geschrieben:</p>
<pre><code class="language-cpp">bool compare(std::pair&lt;std::string, double&gt; &amp;first, 
			 std::pair&lt;std::string, double&gt; &amp;second)
{
	return ( first.first.compare( second.first ) &lt;= 0) ? true : false;
}
</code></pre>
<p>Leider muss ich momentan, eben weil die Referenz const ist, eine neue std::list anlegen, wo die alte reinkopiert wird, und erst bei dieser kann ich dann .sort() aufrufen was nicht gerade effizient ist.</p>
<p>Ich bin mir darüber im klaren das das schlechte Stil ist und das das gefährlich ist, wenn man nicht weiß wer die Liste noch braucht. Aber ich weiß was ich tue <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Welche Möglichkeiten habe ich bzw. wie kann ich das const &quot;wegcasten&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1553046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1553046</guid><dc:creator><![CDATA[IstNunmalso]]></dc:creator><pubDate>Thu, 24 Jul 2008 13:45:24 GMT</pubDate></item><item><title><![CDATA[Reply to const von const std::list wegcasten on Thu, 24 Jul 2008 13:51:56 GMT]]></title><description><![CDATA[<p>dazu gibt es const_cast:</p>
<p>const list&lt;bla&gt; l;<br />
list&lt;bla&gt;&amp; l2 = const_cast&lt;list&lt;bla&gt; &gt;(l);</p>
<p>oder so ähnlich</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1553053</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1553053</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Thu, 24 Jul 2008 13:51:56 GMT</pubDate></item><item><title><![CDATA[Reply to const von const std::list wegcasten on Thu, 24 Jul 2008 14:45:26 GMT]]></title><description><![CDATA[<p>bist du dir sicher, dass die zusätzliche kopie wirklich ein problem ist? hast du es gemessen? wenn es eher eine mikrooptimierung ist, würde ich es mir zweimal überlegen, das const wegzucasten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1553077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1553077</guid><dc:creator><![CDATA[mr. safety]]></dc:creator><pubDate>Thu, 24 Jul 2008 14:45:26 GMT</pubDate></item></channel></rss>