<?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[Fehlende const Features?]]></title><description><![CDATA[<p>Hallo,</p>
<p>geht es nur mir so oder könnte der <code>const</code> Qualifier ein paar mehr Features vertragen? Ich fände folgende Sachen sehr nützlich:</p>
<pre><code>// Konstante freie Funktion, kann keine globalen Variablen verändern
void f() const;
</code></pre>
<pre><code>struct Test 
{
    // Konstante statische Funktion, kann keine statische Member-Variablen verändern 
    static void f() const;
};
</code></pre>
<pre><code>struct Test 
{
    // this_const ist &quot;const&quot; wenn Test objekt als const deklariert, sonst nichts
    int this_const &amp;f() this_const;
};
</code></pre>
<p>Vor allem mit dem letzten könnte man sich doch viel doppelten Code sparen, wäre das nicht sinnvoll (mir ist allerdings kein besserer Name als &quot;this_const&quot; eingefallen^^)?</p>
<p>Ist vielleicht eins (oderer mehrere) dieser Features für die Zukunft geplant? Oder gibt es gute Gründe dagegen, weshalb das bis jetzt noch nicht zur Sprache hinzugefügt wurde?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/333397/fehlende-const-features</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 05:19:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/333397.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Jul 2015 10:21:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehlende const Features? on Thu, 02 Jul 2015 10:21:17 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>geht es nur mir so oder könnte der <code>const</code> Qualifier ein paar mehr Features vertragen? Ich fände folgende Sachen sehr nützlich:</p>
<pre><code>// Konstante freie Funktion, kann keine globalen Variablen verändern
void f() const;
</code></pre>
<pre><code>struct Test 
{
    // Konstante statische Funktion, kann keine statische Member-Variablen verändern 
    static void f() const;
};
</code></pre>
<pre><code>struct Test 
{
    // this_const ist &quot;const&quot; wenn Test objekt als const deklariert, sonst nichts
    int this_const &amp;f() this_const;
};
</code></pre>
<p>Vor allem mit dem letzten könnte man sich doch viel doppelten Code sparen, wäre das nicht sinnvoll (mir ist allerdings kein besserer Name als &quot;this_const&quot; eingefallen^^)?</p>
<p>Ist vielleicht eins (oderer mehrere) dieser Features für die Zukunft geplant? Oder gibt es gute Gründe dagegen, weshalb das bis jetzt noch nicht zur Sprache hinzugefügt wurde?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458508</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Thu, 02 Jul 2015 10:21:17 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Thu, 02 Jul 2015 10:36:50 GMT]]></title><description><![CDATA[<pre><code>&lsqb;&lsqb;gnu::const&rsqb;&rsqb; void f();
</code></pre>
<p>&lt;a href= schrieb:</p>
<blockquote>
<p>GCC-Docs&quot;&gt;Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute below, since function is not allowed to read global memory.</p>
</blockquote>
<p>Hier fallen statische Member Variablen in dieselbe Kategorie.</p>
<p>Deine dritte Idee sieht nicht sonderlich praktikabel aus. Wenn der Typ der Funktion vom Typ des Arguments abhängt, reden wir doch von Templates, oder nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458510</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 02 Jul 2015 10:36:50 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Thu, 02 Jul 2015 12:10:00 GMT]]></title><description><![CDATA[<p>happystudent schrieb:</p>
<blockquote>
<p>Ich fände folgende Sachen sehr nützlich:</p>
<pre><code>// Konstante freie Funktion, kann keine globalen Variablen verändern
void f() const;
</code></pre>
</blockquote>
<p>Ich würde <code>const</code> so nicht überladen wollen. Darf eine const-Member-funktion dann auch keine globalen Variablen mehr ändern? Oder doch? Wie unterscheidet man das? Will man nicht vielleicht beides separat kontrollieren können? Also <code>const</code> für <code>this</code> und was anderes für globale Variablen?</p>
<p>Zu Deiner Frage: Nein, das habe ich bisher nicht vermisst. Das mag daran liegen, dass ich so gut wie keine globalen veränderbaren Variablen benutze.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458535</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 02 Jul 2015 12:10:00 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Thu, 02 Jul 2015 17:53:36 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>Ich würde <code>const</code> so nicht überladen wollen. Darf eine const-Member-funktion dann auch keine globalen Variablen mehr ändern? Oder doch? Wie unterscheidet man das? Will man nicht vielleicht beides separat kontrollieren können? Also <code>const</code> für <code>this</code> und was anderes für globale Variablen?</p>
</blockquote>
<p>Naja, const bezieht sich ja immer auf das &quot;umgebende&quot; Objekt. Wenn man jetzt eine freie Funktion als member im &quot;globalen Main-Objekt&quot; ansieht würds wieder passen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>krümelkacker schrieb:</p>
<blockquote>
<p>Zu Deiner Frage: Nein, das habe ich bisher nicht vermisst. Das mag daran liegen, dass ich so gut wie keine globalen veränderbaren Variablen benutze.</p>
</blockquote>
<p>Ich auch nicht, hatte das nur der Vollständigkeit halber dabei. Aber bei statischen Variablen fänd ich das schon teilweise gut.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Deine dritte Idee sieht nicht sonderlich praktikabel aus. Wenn der Typ der Funktion vom Typ des Arguments abhängt, reden wir doch von Templates, oder nicht?</p>
</blockquote>
<p>Ja, also mich nervt das halt vor allem bei Iteratoren. Da implementiert man letztendlich zweimal genau das gleiche Ding, nur dass man einmal überall const hinter die Funktion schreibt...</p>
<p>Oder von mir aus auch als Template:</p>
<pre><code>auto const_it = my_vector.begin&lt;const&gt;();
</code></pre>
<p>Wär doch schön <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458567</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Thu, 02 Jul 2015 17:53:36 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Thu, 02 Jul 2015 21:54:40 GMT]]></title><description><![CDATA[<p>happystudent schrieb:</p>
<blockquote>
<p>Da implementiert man letztendlich zweimal genau das gleiche Ding, nur dass man einmal überall const hinter die Funktion schreibt...</p>
</blockquote>
<p>Das kann man umgehen, indem die nicht-const Funktion die const Funktion mit entsprechenden casts aufruft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458580</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Thu, 02 Jul 2015 21:54:40 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Fri, 03 Jul 2015 07:18:03 GMT]]></title><description><![CDATA[<p>Jockelx schrieb:</p>
<blockquote>
<p>Das kann man umgehen, indem die nicht-const Funktion die const Funktion mit entsprechenden casts aufruft.</p>
</blockquote>
<p>Ja, aber deswegen muss man doch trotzdem den ganzen Code duplizieren, einmal für <code>xyz::iterator</code> und <code>xyz::const_iterator</code> ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458584</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Fri, 03 Jul 2015 07:18:03 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Sat, 04 Jul 2015 08:19:08 GMT]]></title><description><![CDATA[<p>happystudent schrieb:</p>
<blockquote>
<p>Ich fände folgende Sachen sehr nützlich:</p>
</blockquote>
<p>Du befürchtest doch nur, daß jemand C++ schneller lernen kann als es verkompliziert wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458676</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 04 Jul 2015 08:19:08 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Sat, 04 Jul 2015 16:43:13 GMT]]></title><description><![CDATA[<p>happystudent schrieb:</p>
<blockquote>
<p>Naja, const bezieht sich ja immer auf das &quot;umgebende&quot; Objekt. Wenn man jetzt eine freie Funktion als member im &quot;globalen Main-Objekt&quot; ansieht würds wieder passen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Das reicht doch nicht. Warum darf eine const Memberfunktion beliebig im globalen Scope rumpfuschen und eine freie Funktion nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458708</guid><dc:creator><![CDATA[Mechanics]]></dc:creator><pubDate>Sat, 04 Jul 2015 16:43:13 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlende const Features? on Mon, 06 Jul 2015 11:18:05 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Du befürchtest doch nur, daß jemand C++ schneller lernen kann als es verkompliziert wird.</p>
</blockquote>
<p>Naja, statische Funktionen const machen zu dürfen wäre jetzt glaub ich nicht der Komplexitäts-Overkill <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>Bei der globalen Funktion muss ich euch Recht geben, es wäre wohl logisch nicht vertretbar dass konstante Member Funktionen im globalen Scope Dinge ändern dürfen und konstante freie Funktionen nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2458829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2458829</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Mon, 06 Jul 2015 11:18:05 GMT</pubDate></item></channel></rss>