<?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[Alle Elemente im Container gleich?]]></title><description><![CDATA[<p>Welche STL-Algorithmen würdet ihr verwenden, um zu prüfen, ob alle Elemente in einem Container gleich sind? Eine Möglichkeit wäre:</p>
<pre><code>bool equal = std::all_of(c.begin(), c.end(), [&amp;c] (T elem) { return elem == c.front(); });
</code></pre>
<p>Es gibt viele Möglichkeiten, aber die anderen scheinen mir noch komplizierter, weil man zusätzlich einen Iterator vergleichen muss. Würdet ihr eine herkömmliche Schleife verwenden?</p>
<p>- z0r0id <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319962/alle-elemente-im-container-gleich</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 14:49:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319962.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 Sep 2013 14:03:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 14:03:48 GMT]]></title><description><![CDATA[<p>Welche STL-Algorithmen würdet ihr verwenden, um zu prüfen, ob alle Elemente in einem Container gleich sind? Eine Möglichkeit wäre:</p>
<pre><code>bool equal = std::all_of(c.begin(), c.end(), [&amp;c] (T elem) { return elem == c.front(); });
</code></pre>
<p>Es gibt viele Möglichkeiten, aber die anderen scheinen mir noch komplizierter, weil man zusätzlich einen Iterator vergleichen muss. Würdet ihr eine herkömmliche Schleife verwenden?</p>
<p>- z0r0id <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351590</guid><dc:creator><![CDATA[z0r0id]]></dc:creator><pubDate>Tue, 10 Sep 2013 14:03:48 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 14:08:44 GMT]]></title><description><![CDATA[<p>Mir ist grad noch was eingefallen, das ohne Lambda-Expression auskommt:</p>
<pre><code>bool equal = std::count(c.begin(), c.end(), c.front()) == c.size();
</code></pre>
<p>Allerdings müssen hier in jedem Fall alle Elemente durchlaufen werden.</p>
<p>- z0r0id <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351592</guid><dc:creator><![CDATA[z0r0id]]></dc:creator><pubDate>Tue, 10 Sep 2013 14:08:44 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 14:19:47 GMT]]></title><description><![CDATA[<p>Keine Schleife, eher deine Variante 1. Variante 2 hat kein early exit wenn ein Element innen drin ungleich ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351595</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Tue, 10 Sep 2013 14:19:47 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 14:30:22 GMT]]></title><description><![CDATA[<p>Verlesen. Ja, was spricht gg Variante1?</p>
<p>Nachteil ist aber, dass bei nem leeren Container true herauskommt, jdf. bei meinem Test.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351598</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Tue, 10 Sep 2013 14:30:22 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 14:33:42 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Nachteil ist aber, dass bei nem leeren Container true herauskommt, jdf. bei meinem Test.</p>
</blockquote>
<p>Was soll denn sonst rauskommen? Es sind doch alle Elemente gleich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351601</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351601</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Tue, 10 Sep 2013 14:33:42 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 14:35:36 GMT]]></title><description><![CDATA[<p>Ich schlag mal</p>
<pre><code class="language-cpp">c.empty() || std::equal(std::begin(c), std::prev(std::end(c)), std::next(std::begin(c)));
// bzw.
!c.empty() &amp;&amp; std::equal(std::begin(c), std::prev(std::end(c)), std::next(std::begin(c)));
</code></pre>
<p>vor. Wobei die Semantik subtil anders ist, wenn operator== nicht transitiv ist, aber in dem Fall hat man sowieso ein Definitionsproblem und muss genauer nachdenken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351602</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351602</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Tue, 10 Sep 2013 14:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 14:52:54 GMT]]></title><description><![CDATA[<blockquote>
<p>Nachteil ist aber, dass bei nem leeren Container true herauskommt, jdf. bei meinem Test.</p>
</blockquote>
<p>Ist konsistent mit der Mathematik.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351609</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Tue, 10 Sep 2013 14:52:54 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 17:02:08 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<blockquote>
<p>Nachteil ist aber, dass bei nem leeren Container true herauskommt, jdf. bei meinem Test.</p>
</blockquote>
<p>Ist konsistent mit der Mathematik.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /><br />
Man definiert schließlich das Gleichsein aller Elemente auch so, dass es nicht zwei Elemente gibt die verschieden sind.</p>
<p>Ich werfe auch noch</p>
<pre><code>std::mismatch( std::begin(c), std::end(c), std::next(std::begin(c)), std::end(c) ).first == std::end(c)
</code></pre>
<p>in den Ring. (Ungetestet)</p>
<p>Edit: Keine Ahnung, was die Lösung, soll, das ist eigentlich nur seldons aber Invers (Teste nicht ob alle gleich sind sondern finde den ersten Mismatch).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351633</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 10 Sep 2013 17:02:08 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Tue, 10 Sep 2013 22:57:41 GMT]]></title><description><![CDATA[<blockquote>
<p>Man definiert schließlich das Gleichsein aller Elemente auch so, dass es nicht zwei Elemente gibt die verschieden sind.</p>
</blockquote>
<p>Waehle eine Erklaerung aus: <a href="http://math.stackexchange.com/questions/202452/why-is-predicate-all-as-in-allset-true-if-the-set-is-empty" rel="nofollow">http://math.stackexchange.com/questions/202452/why-is-predicate-all-as-in-allset-true-if-the-set-is-empty</a> (Moege es nicht die rockenden Kinder sein).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351728</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Tue, 10 Sep 2013 22:57:41 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 13:58:01 GMT]]></title><description><![CDATA[<p>Danke für die Ideen. Ich muss sagen, sowas simples wie zu prüfen, ob alle Elemente gleich sind, ist wahnsinnig kompliziert in C++.</p>
<p>Nochwas komplett unnötiges, das mir aufgefallen ist: Bei</p>
<pre><code>std::count(c.begin(), c.end(), c.front()) == c.size();
</code></pre>
<p>ist oberlästig, dass ich eine Compilerwarnung wegen signed/unsigned-Konflikt erhalte. Wer hatte wieder die brilliante Idee, in std::count() einen anderen Typen als std::size_t zurückzugeben? Wie oft sind Anzahlen negativ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>- z0r0id <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351853</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351853</guid><dc:creator><![CDATA[z0r0id]]></dc:creator><pubDate>Wed, 11 Sep 2013 13:58:01 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 14:04:55 GMT]]></title><description><![CDATA[<blockquote>
<p>Danke für die Ideen. Ich muss sagen, sowas simples wie zu prüfen, ob alle Elemente gleich sind, ist wahnsinnig kompliziert in C++.</p>
</blockquote>
<p>Nur weil es viele Moeglichkeiten gibt? Nein. Was soll an deiner Variante 1 kompliziert sein?</p>
<blockquote>
<p>Wie oft sind Anzahlen negativ?</p>
</blockquote>
<blockquote>
<p>Der Klassiker:<br />
Ein Ingenieur, ein Physiker und ein Mathematiker beobachten einen Aufzug, und sehen, wie im Erdgeschoss zwei Leute in den Aufzug einsteigen, und im ersten Stock drei aussteigen.<br />
Meint der Ingenieur: &quot;Da war wohl schon einer im Aufzug!&quot;<br />
Der Physiker: &quot;Das muss ein Messfehler sein!&quot;<br />
Und der Mathematiker: &quot;Wenn jetzt einer in den Aufzug einsteigt, ist der Aufzug leer!&quot;</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2351856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351856</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 11 Sep 2013 14:04:55 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 14:09:43 GMT]]></title><description><![CDATA[<p><a href="http://stackoverflow.com/questions/7505083/why-does-the-c-standard-algorithm-count-return-a-ptrdiff-t-instead-of-size-t" rel="nofollow">http://stackoverflow.com/questions/7505083/why-does-the-c-standard-algorithm-count-return-a-ptrdiff-t-instead-of-size-t</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351860</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 11 Sep 2013 14:09:43 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 14:32:16 GMT]]></title><description><![CDATA[<p>Was ist mit <code>equal_range</code> ? Kommt ohne Schleife aus und terminiert beim ersten Mismatch.</p>
<pre><code>bool all_equal( const std::vector&lt;int&gt;&amp; v )
{
   typedef std::vector&lt;int&gt;::iterator iterator;
   typedef std::pair&lt;interator,iterator&gt; iter_pair;

   if( !v.empty() )
   {
      iter_pair p = equal_range( begin( v ), end( v ), v.front() );
      return p.first == begin( v ) &amp;&amp; p.second == end( v );
   }
   return true;
}
</code></pre>
<p>PS:<br />
Ist auch nicht eleganter als <code>std::mismatch</code> ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351874</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Wed, 11 Sep 2013 14:32:16 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 14:37:38 GMT]]></title><description><![CDATA[<blockquote>
<p>Kommt ohne Schleife aus</p>
</blockquote>
<p>pardon? Intern...?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351883</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351883</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 11 Sep 2013 14:37:38 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 14:38:24 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Was ist mit <code>equal_range</code> ? Kommt ohne Schleife aus und terminiert beim ersten Mismatch.</p>
</blockquote>
<p>Ich glaub ich würd dich zur Erschießung vorschlagen, wenn du mir sowas anbötest. <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/2351884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351884</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 11 Sep 2013 14:38:24 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 15:11:40 GMT]]></title><description><![CDATA[<p>Bieten die STL Container -- ausgenommen vielleicht unordered_* -- nicht von sich aus schon relationale Operatoren an?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351899</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 11 Sep 2013 15:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 15:19:50 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Was ist mit <code>equal_range</code> ? Kommt ohne Schleife aus und terminiert beim ersten Mismatch.</p>
</blockquote>
<p>1. Nur für sortiert<br />
2. equal_range nutzt intern lower_bound und upper_bound, was der binary-search-Version von find entspricht. Man hätte also keinen Gewinn, nur mehr overhead.</p>
<p>krümelkacker schrieb:</p>
<blockquote>
<p>Bieten die STL Container -- ausgenommen vielleicht unordered_* -- nicht von sich aus schon relationale Operatoren an?!</p>
</blockquote>
<p>Nur für Vergleiche zwischen zwei Containern. Hier geht es aber darum, die Elemente innerhalb eines Containers zu vergleichen.</p>
<p>mismatch ist schon das Beste.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351907</guid><dc:creator><![CDATA[Marthog]]></dc:creator><pubDate>Wed, 11 Sep 2013 15:19:50 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 15:22:12 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>pardon? Intern...?</p>
</blockquote>
<p>Interessiert niemanden, alle vorgeschlagenen Moeglichkeiten basieren auf Schleifen. Koennten aber auch end-rekursiv implementiert sein. Duerfen sie laut Standard rekursiv sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351909</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351909</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 11 Sep 2013 15:22:12 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 15:28:11 GMT]]></title><description><![CDATA[<p>Selber einen ALgo schreiben? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351912</guid><dc:creator><![CDATA[hmmmmmmmm]]></dc:creator><pubDate>Wed, 11 Sep 2013 15:28:11 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 15:40:44 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<p>pardon? Intern...?</p>
</blockquote>
<p>Interessiert niemanden, alle vorgeschlagenen Moeglichkeiten basieren auf Schleifen. Koennten aber auch end-rekursiv implementiert sein. Duerfen sie laut Standard rekursiv sein?</p>
</blockquote>
<blockquote>
<p>Except where explicitly specified in this standard, it is implementation-defined which functions in the Standard C++ library may be recursively reentered.</p>
</blockquote>
<p>Das ist alles, was überhaupt zu Rekursion in dem Library-Abschnitt steht.</p>
<p>Also ja, das dürfen sie wahrscheinlich. Ist schließlich alles Implementationsspezifisch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351917</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 11 Sep 2013 15:40:44 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 15:49:17 GMT]]></title><description><![CDATA[<p>Also wenn sortiert, würde ich einfach front() auf back()-Gleichheit prüfen.</p>
<p>Sonst geht's wohl nicht einfacher als mit nem std::algorithm + nem kleinen Lambda, ich bin immer noch für V1.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351922</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351922</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Wed, 11 Sep 2013 15:49:17 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 16:00:01 GMT]]></title><description><![CDATA[<p>Ich finde seldons Variante am elegantesten.</p>
<p>Auch wenn ein QC-Kommentar in allen Fällen sowieso angebracht ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351928</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 11 Sep 2013 16:00:01 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 16:19:20 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Ich finde seldons Variante am elegantesten.</p>
</blockquote>
<p>Ja, du findest Write-Only-Code generell elegant <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="😉"
    /> Ich musste seldons Code etwa 20 Sekunden lang anschauen, bis ich verstanden habe, was er überhaupt tut. Die zusätzliche Abfrage auf empty() verwirrt nur noch mehr.</p>
<p>krümelkacker schrieb:</p>
<blockquote>
<p>Bieten die STL Container -- ausgenommen vielleicht unordered_* -- nicht von sich aus schon relationale Operatoren an?!</p>
</blockquote>
<p>Was bringt das hier? Um zwei Container zu vergleichen, müsste ich ja eine Kopie erstellen.</p>
<p>knivil schrieb:</p>
<blockquote>
<p>Nur weil es viele Moeglichkeiten gibt? Nein. Was soll an deiner Variante 1 kompliziert sein?</p>
</blockquote>
<p>Nein, weil die simpelste Möglichkeit bereits Lambda-Ausdrücke (mit Capture) erfordert. Schlussendlich hat man recht viel Boilerplate-Syntax.</p>
<p>Ausserdem drückt man mit ihr aus: &quot;prüfe für alle Elemente, ob sie gleich dem ersten Element sind&quot;. Das ist aber ein Implementierungsdetail, schöner wäre &quot;prüfe alle Elemente auf Gleichheit&quot;. Muss ich halt selbst eine Abstraktionsebene höher schreiben.</p>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>ich bin immer noch für V1.</p>
</blockquote>
<p>Ja, ich machs jetzt auch so, kleinstes Übel. Oder bei Negation mit std::any_of und !=.</p>
<p>- z0r0id <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351930</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351930</guid><dc:creator><![CDATA[z0r0id]]></dc:creator><pubDate>Wed, 11 Sep 2013 16:19:20 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 16:23:18 GMT]]></title><description><![CDATA[<blockquote>
<p>Ja, du findest Write-Only-Code generell elegant</p>
</blockquote>
<p>Nein. Schon gar nicht in Anwendungscode. Ich finde nur die Syntax von Lambdas (gerade so direkt in der Argumentenliste) sehr hässlich und nicht <a href="http://de.wikipedia.org/wiki/Literate_programming" rel="nofollow">literarisch</a>.</p>
<blockquote>
<p>Ich musste seldons Code etwa 20 Sekunden lang anschauen, bis ich verstanden habe, was er überhaupt tut.</p>
</blockquote>
<p>Ich nicht, ich kenne den Trick schon längst. Und den STL-Algorithmus.</p>
<blockquote>
<p>Die zusätzliche Abfrage auf empty() verwirrt nur noch mehr.</p>
</blockquote>
<p>Hä? Die ist nur optional, für alle die es so brauchen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351931</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 11 Sep 2013 16:23:18 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 16:27:22 GMT]]></title><description><![CDATA[<p>Kommt schon.</p>
<pre><code>std::all_of(c.begin(), c.end(), [&amp;c] (T elem) { return elem == c.front(); })
</code></pre>
<p>vs</p>
<pre><code>std::equal(std::begin(c), std::prev(std::end(c)), std::next(std::begin(c)))
</code></pre>
<p>Das ist doch kein Vergleich.<br />
Mit using namespace std; davor:</p>
<pre><code>equal(begin(c), prev(end(c)), next(begin(c)))
</code></pre>
<p>Kommentiert muss der Code in beiden Fällen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351932</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 11 Sep 2013 16:27:22 GMT</pubDate></item><item><title><![CDATA[Reply to Alle Elemente im Container gleich? on Wed, 11 Sep 2013 16:31:34 GMT]]></title><description><![CDATA[<blockquote>
<p>Nein, weil die simpelste Möglichkeit bereits Lambda-Ausdrücke (mit Capture) erfordert. Schlussendlich hat man recht viel Boilerplate-Syntax</p>
</blockquote>
<p>Akzeptiert, lambda ist tatsaechlich Boilerplate.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2351934</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2351934</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 11 Sep 2013 16:31:34 GMT</pubDate></item></channel></rss>