<?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[Probleme mit Lamdda bei find_if zum Durchsuchen eines Vectors]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe gerade ein Verständnis beim Durchsuchen eines std::vector. Normaler Weise klappt es immer problems mit Lamddas. nur diesmal muss ich innerhalb des Lamddas auf eine Memberfunktion der Klasse zugreifen.</p>
<p>Ich habe die Problemstellung mit dem folgden Programm nachgestellt.</p>
<pre><code>#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;

class test
{
  vector&lt;int&gt; v;

  int umwandel(const int i) {return i * 10;}

public:
  test(const int i1, const int i2, const int i3, const int i4, const int i5)
  {
    v.push_back(i1);
    v.push_back(i2);
    v.push_back(i3);
    v.push_back(i4);
    v.push_back(i5);
  }

  void foo(const int i)
  {
     auto it = find_if(begin(v), end(v), [&amp;](const int id) -&gt; bool {
        return umwandel(id) = i;
     });
     if (it != end(v))
     {
        // do something
     }
   }
};

int main()
{	
  test t(1, 2, 3, 4, 5);
  t.foo(10);
}
</code></pre>
<p>Hier liefert mir VS 2010 jetzt in Zeile 25 die Fehlermeldung</p>
<p>&quot;error C2106: '=': Linker Operand muss ein L-Wert sein&quot;</p>
<p>Es ist mir klar, weil umwandeln gehört zur Klasse test.</p>
<p>Wie kann ich hier nach dem Wert suchen, eine Lösung mit einer For schleife zum Durchlaufen der Schleife ist mir bekannt.</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327916/probleme-mit-lamdda-bei-find_if-zum-durchsuchen-eines-vectors</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 15:27:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327916.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Sep 2014 12:57:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit Lamdda bei find_if zum Durchsuchen eines Vectors on Thu, 11 Sep 2014 12:57:23 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe gerade ein Verständnis beim Durchsuchen eines std::vector. Normaler Weise klappt es immer problems mit Lamddas. nur diesmal muss ich innerhalb des Lamddas auf eine Memberfunktion der Klasse zugreifen.</p>
<p>Ich habe die Problemstellung mit dem folgden Programm nachgestellt.</p>
<pre><code>#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;

class test
{
  vector&lt;int&gt; v;

  int umwandel(const int i) {return i * 10;}

public:
  test(const int i1, const int i2, const int i3, const int i4, const int i5)
  {
    v.push_back(i1);
    v.push_back(i2);
    v.push_back(i3);
    v.push_back(i4);
    v.push_back(i5);
  }

  void foo(const int i)
  {
     auto it = find_if(begin(v), end(v), [&amp;](const int id) -&gt; bool {
        return umwandel(id) = i;
     });
     if (it != end(v))
     {
        // do something
     }
   }
};

int main()
{	
  test t(1, 2, 3, 4, 5);
  t.foo(10);
}
</code></pre>
<p>Hier liefert mir VS 2010 jetzt in Zeile 25 die Fehlermeldung</p>
<p>&quot;error C2106: '=': Linker Operand muss ein L-Wert sein&quot;</p>
<p>Es ist mir klar, weil umwandeln gehört zur Klasse test.</p>
<p>Wie kann ich hier nach dem Wert suchen, eine Lösung mit einer For schleife zum Durchlaufen der Schleife ist mir bekannt.</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417035</guid><dc:creator><![CDATA[Augustus]]></dc:creator><pubDate>Thu, 11 Sep 2014 12:57:23 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Lamdda bei find_if zum Durchsuchen eines Vectors on Thu, 11 Sep 2014 13:08:02 GMT]]></title><description><![CDATA[<p>Du möchtest wohl</p>
<pre><code>return umwandel(id) == i;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2417037</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417037</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Thu, 11 Sep 2014 13:08:02 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Lamdda bei find_if zum Durchsuchen eines Vectors on Thu, 11 Sep 2014 13:17:23 GMT]]></title><description><![CDATA[<pre><code>[this]
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2417040</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417040</guid><dc:creator><![CDATA[lambdaa]]></dc:creator><pubDate>Thu, 11 Sep 2014 13:17:23 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Lamdda bei find_if zum Durchsuchen eines Vectors on Thu, 11 Sep 2014 13:25:01 GMT]]></title><description><![CDATA[<p>Mist! Tippfehler! Ja jetzt läuft mein Testprogramm!</p>
<p>icarus2 schrieb:</p>
<blockquote>
<p>Du möchtest wohl</p>
<pre><code>return umwandel(id) == i;
</code></pre>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2417043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417043</guid><dc:creator><![CDATA[Augustus]]></dc:creator><pubDate>Thu, 11 Sep 2014 13:25:01 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Lamdda bei find_if zum Durchsuchen eines Vectors on Thu, 11 Sep 2014 13:36:41 GMT]]></title><description><![CDATA[<p>Ich kann mir nur sehr schwer vorstellen dass du Lambdas verwendest, aber einen so banalen Syntax-Fehler nicht (selber) findest.</p>
<p>Außerdem ist dein Lambda-Capture mMn. nicht optimal. Es muss <code>i</code> capturen - das kann aber by copy geschehen, wodurch die unnötige Indirektion schwindet. Ebenso wie bei <code>this</code> . Also sollte der capture-default zu <code>=</code> geändert werden. Somit kann das Ganze zu</p>
<pre><code>[=] (int id) {return umwandel(id) == i;}
</code></pre>
<p>verkürzt werden.</p>
<pre><code>[i, this] (int id) {return umwandel(id) == i;}
</code></pre>
<p>ist auch möglich (und wird von einigen bevorzugt).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417046</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 11 Sep 2014 13:36:41 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Lamdda bei find_if zum Durchsuchen eines Vectors on Thu, 11 Sep 2014 14:00:05 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>sorry, aber beim Versuch ein minimales Testbeispiel zu schreiben, ist mir Tippfehler unterlaufen.</p>
<p>Das reale Programm ist viel, viel komplexer. MFC Programm und bei der abgeleiteten Funktion handelt es sich um GetDlgItem. Das find_if wird benutzt in einer Klasse die von CDialogEx abgeleitet wurde. Den Code kann ich hier aber nicht reinsetzen.</p>
<p>Suche ich halt weiter und benutze die for-Schleife. Wollte halt was lernen.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Ich kann mir nur sehr schwer vorstellen dass du Lambdas verwendest, aber einen so banalen Syntax-Fehler nicht (selber) findest.</p>
<p>Außerdem ist dein Lambda-Capture mMn. nicht optimal. Es muss <code>i</code> capturen - das kann aber by copy geschehen, wodurch die unnötige Indirektion schwindet. Ebenso wie bei <code>this</code> . Also sollte der capture-default zu <code>=</code> geändert werden. Somit kann das Ganze zu</p>
<pre><code>[=] (int id) {return umwandel(id) == i;}
</code></pre>
<p>verkürzt werden.</p>
<pre><code>[i, this] (int id) {return umwandel(id) == i;}
</code></pre>
<p>ist auch möglich (und wird von einigen bevorzugt).</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2417049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417049</guid><dc:creator><![CDATA[Augustus]]></dc:creator><pubDate>Thu, 11 Sep 2014 14:00:05 GMT</pubDate></item></channel></rss>