<?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[mapcar in C++11]]></title><description><![CDATA[<p>Ich würde gerne mapcar aus Lisp in C++11 implementieren:</p>
<pre><code class="language-cpp">template &lt;typename ListType, typename Map&gt; ListType mapcar(Map LambdaFunction, const ListType&amp; List)
{
	ListType result;
	transform(List.begin(), List.end(), back_inserter(result), LambdaFunction);
	return result;
}
</code></pre>
<p>Geht das besser?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/297129/mapcar-in-c-11</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 14:38:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/297129.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Dec 2011 17:44:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 17:44:36 GMT]]></title><description><![CDATA[<p>Ich würde gerne mapcar aus Lisp in C++11 implementieren:</p>
<pre><code class="language-cpp">template &lt;typename ListType, typename Map&gt; ListType mapcar(Map LambdaFunction, const ListType&amp; List)
{
	ListType result;
	transform(List.begin(), List.end(), back_inserter(result), LambdaFunction);
	return result;
}
</code></pre>
<p>Geht das besser?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158873</guid><dc:creator><![CDATA[huuuuuuuuuuuu]]></dc:creator><pubDate>Mon, 19 Dec 2011 17:44:36 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:06:23 GMT]]></title><description><![CDATA[<p>Also ich versteh nicht ganz warum du das nochmal in eine extra Funktion packen willst, wenn du mit <code>std::transform</code> sowieso das Ergebnis erreichen kannst.</p>
<p>Außerdem, was ist wenn dein Listentyp keinen <code>std::back_inserter</code> unterstützt, wie z.B. <code>std::queue</code> ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158888</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:06:23 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:08:21 GMT]]></title><description><![CDATA[<p>weil ich transform nicht kannte <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2158890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158890</guid><dc:creator><![CDATA[huuuuuuuuuuuu]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:08:21 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:37:06 GMT]]></title><description><![CDATA[<p>Und was ist hier falsch:</p>
<pre><code class="language-cpp">template &lt;typename InputListType, typename OutputListType, typename Map&gt; OutputListType mapcar(Map LambdaFunction, const InputListType&amp; liste)
{
	OutputListType result;
	for (const auto elt: liste)
        result.push_back(LambdaFunction(elt));
	return result;
}

int main()
{
    vector&lt;int&gt; a({1,2,3,4,5});
    vector&lt;double&gt; b = mapcar([](int i) -&gt; double{return i*2.5;}, a);

    for (auto const elt: b)
        cout &lt;&lt; elt &lt;&lt; &quot; &quot;;
    return 0;
}
</code></pre>
<p>error: conversion from ‘std::vector&lt;int&gt;’ to non-scalar type ‘std::vector&lt;double&gt;’ requested|<br />
||=== Build finished: 1 errors, 0 warnings ===|</p>
<p>&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158913</guid><dc:creator><![CDATA[huuuuuuuuuuuu]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:37:06 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:37:32 GMT]]></title><description><![CDATA[<p>Ok das ist verwunderlich weil du es ja in deinem Ausgangspost verwendest <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2158914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158914</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:37:32 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:44:38 GMT]]></title><description><![CDATA[<p>huuuuuuuuuuuu schrieb:</p>
<blockquote>
<p>error: conversion from ‘std::vector&lt;int&gt;’ to non-scalar type ‘std::vector&lt;double&gt;’ requested|<br />
||=== Build finished: 1 errors, 0 warnings ===|</p>
</blockquote>
<p>Ist das nicht ziemlich eindeutig? Du kannst keinen vector&lt;int&gt; einfach durch Zuweisung in einen vector&lt;double&gt; konvertieren!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158920</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158920</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:44:38 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:46:13 GMT]]></title><description><![CDATA[<p>Aber mein mapcar hat doch extra dafür einen OutputListType.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158923</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158923</guid><dc:creator><![CDATA[huuuuuuuuuuuu]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:46:13 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:47:23 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">vector&lt;double&gt; b =
        mapcar&lt;vector&lt;double&gt; &gt;([](int i) -&gt; double
                {return i*2.5;},
        a);
</code></pre>
<p>so funzt es.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158925</guid><dc:creator><![CDATA[huuuuuuuuuuuu]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:47:23 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 18:51:23 GMT]]></title><description><![CDATA[<p>Wieso meckert er eigentlich nicht schon an der Stelle, an der er es nicht schafft, für OutputListType einen Typen herzuleiten? <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="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158928</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 19 Dec 2011 18:51:23 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 19:05:40 GMT]]></title><description><![CDATA[<p><a href="http://ideone.com/cnJie" rel="nofollow">http://ideone.com/cnJie</a></p>
<p>Wofür steht eigentlich &quot;mapcar&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158932</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 19 Dec 2011 19:05:40 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 19:18:56 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">template &lt;typename T&gt;
T make();
 
template &lt;typename InType, typename Function&gt;
auto mapcar(std::vector&lt;InType&gt; const&amp; in, Function const&amp; func) -&gt; std::vector&lt;decltype(func(make&lt;InType&gt;()))&gt;
{
        typedef decltype(func(make&lt;InType&gt;())) OutType;
        // ...
}
</code></pre>
</blockquote>
<p>Warum einfach, wenns auch kompliziert geht <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>
<pre><code class="language-cpp">template &lt;typename InType, typename Function,
          typename OutType = typename std::result_of&lt;Function(InType)&gt;::type &gt;
std::vector&lt;OutType&gt; mapcar(std::vector&lt;InType&gt; const&amp; in, Function const&amp; func)
{
  // ...
}
</code></pre>
<p>BTW: mapcar kommt von map wie mappen und car wie <a href="http://en.wikipedia.org/wiki/CAR_and_CDR" rel="nofollow">CAR</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158945</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158945</guid><dc:creator><![CDATA[std__result_of]]></dc:creator><pubDate>Mon, 19 Dec 2011 19:18:56 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 19:20:56 GMT]]></title><description><![CDATA[<p>Weil ich daran halt nicht gedacht habe. Du hättest es ja selbst posten können, wenn du so schlau bist. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2158948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158948</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 19 Dec 2011 19:20:56 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 20:32:35 GMT]]></title><description><![CDATA[<p>std__result_of schrieb:</p>
<blockquote>
<p>BTW: mapcar kommt von map wie mappen und car wie <a href="http://en.wikipedia.org/wiki/CAR_and_CDR" rel="nofollow">CAR</a></p>
</blockquote>
<p>Hihi, was für eine Abkürzung: &quot;<em>Contents of the Address part of Register number</em>&quot;. Zweck sofort ersichtlich <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/2158976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158976</guid><dc:creator><![CDATA[uh]]></dc:creator><pubDate>Mon, 19 Dec 2011 20:32:35 GMT</pubDate></item><item><title><![CDATA[Reply to mapcar in C++11 on Mon, 19 Dec 2011 21:07:55 GMT]]></title><description><![CDATA[<p><code>car</code> , <code>cdr</code> , <code>cadr</code> , <code>cadadr</code> , ... aber wahrscheinlich sind die meisten zu jung dafuer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2158997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2158997</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 19 Dec 2011 21:07:55 GMT</pubDate></item></channel></rss>