<?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[Lambda Funktion runde Klammern]]></title><description><![CDATA[<p>Hallo, ich versuche gerade die Lambda Funktionen zu verstehen, jedoch hakts bei mir an der Parameterliste. Wenn ich sowas habe</p>
<pre><code class="language-cpp">std::vector&lt;int&gt; some_list;
int total = 0;
std::for_each(some_list.begin(), some_list.end(), [&amp;total](int x) {
  total += x;
});
</code></pre>
<p>steht das int x ja für den Wert im vector oder?<br />
Doch wenn ich sowas habe</p>
<pre><code class="language-cpp">std::vector&lt;MyClass&gt; some_list;
std::string total = 0;
std::for_each(some_list.begin(), some_list.end(), [&amp;total](int x, int y, std::string z) {
  total += x + y + z;
});
</code></pre>
<p>was ist dann x, y und z?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/282061/lambda-funktion-runde-klammern</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 09:37:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/282061.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Feb 2011 12:11:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Lambda Funktion runde Klammern on Sun, 13 Feb 2011 12:11:27 GMT]]></title><description><![CDATA[<p>Hallo, ich versuche gerade die Lambda Funktionen zu verstehen, jedoch hakts bei mir an der Parameterliste. Wenn ich sowas habe</p>
<pre><code class="language-cpp">std::vector&lt;int&gt; some_list;
int total = 0;
std::for_each(some_list.begin(), some_list.end(), [&amp;total](int x) {
  total += x;
});
</code></pre>
<p>steht das int x ja für den Wert im vector oder?<br />
Doch wenn ich sowas habe</p>
<pre><code class="language-cpp">std::vector&lt;MyClass&gt; some_list;
std::string total = 0;
std::for_each(some_list.begin(), some_list.end(), [&amp;total](int x, int y, std::string z) {
  total += x + y + z;
});
</code></pre>
<p>was ist dann x, y und z?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2020437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2020437</guid><dc:creator><![CDATA[Lambda0x]]></dc:creator><pubDate>Sun, 13 Feb 2011 12:11:27 GMT</pubDate></item><item><title><![CDATA[Reply to Lambda Funktion runde Klammern on Sun, 13 Feb 2011 12:27:07 GMT]]></title><description><![CDATA[<blockquote>
<p>was ist dann x, y und z?</p>
</blockquote>
<p>Das dürfte gar nicht kompileren, weil std::for_each dem Funktor (in diesem Fall die Lambda-Funktion) ein Objekt der Klasse MyClass übergibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2020443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2020443</guid><dc:creator><![CDATA[ncc]]></dc:creator><pubDate>Sun, 13 Feb 2011 12:27:07 GMT</pubDate></item><item><title><![CDATA[Reply to Lambda Funktion runde Klammern on Sun, 13 Feb 2011 12:53:30 GMT]]></title><description><![CDATA[<p>Vielleicht hilft es Dir, wenn Du eine Implementierung von for_each siehst:</p>
<pre><code class="language-cpp">template&lt;class Iter, class Func&gt;
Func for_each(Iter beg, Iter end, Func f)
{
  while (beg!=end) {
    f(*beg);
    ++beg;
  }
  return f;
}
</code></pre>
<p>Und *beg ist in Deinem Fall ein Lvalue-Ausdruck vom Typ MyClass.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2020463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2020463</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 13 Feb 2011 12:53:30 GMT</pubDate></item></channel></rss>