<?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[function -object&#x2F;pointer als template argument]]></title><description><![CDATA[<p>Hi,</p>
<p>ich probier mal mein Problem so kurz wie möglich zu beschreiben</p>
<pre><code>template&lt;T , SOMETHING&gt;
SOMETHING::return_value run(T val, SOMETHING f) { return f(val) }
</code></pre>
<p>SOMETHING kann sein<br />
Function porinter<br />
Function object (std::function, Functor)<br />
oder was immer mir std::bind zurückgibt.</p>
<p>die Frage ist also, was ist SOMETHING?</p>
<p>geht das überhaut?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326533/function-object-pointer-als-template-argument</link><generator>RSS for Node</generator><lastBuildDate>Sat, 30 May 2026 18:04:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326533.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Jun 2014 10:29:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 10:29:17 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich probier mal mein Problem so kurz wie möglich zu beschreiben</p>
<pre><code>template&lt;T , SOMETHING&gt;
SOMETHING::return_value run(T val, SOMETHING f) { return f(val) }
</code></pre>
<p>SOMETHING kann sein<br />
Function porinter<br />
Function object (std::function, Functor)<br />
oder was immer mir std::bind zurückgibt.</p>
<p>die Frage ist also, was ist SOMETHING?</p>
<p>geht das überhaut?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2405164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405164</guid><dc:creator><![CDATA[kurze_frage_atwork]]></dc:creator><pubDate>Mon, 23 Jun 2014 10:29:17 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 10:34:06 GMT]]></title><description><![CDATA[<blockquote>
<p>geht das überhaut?</p>
</blockquote>
<p>Nein, nicht so wie in deinem Codeschnipsel.</p>
<p>Suchst du</p>
<pre><code>template&lt; typename T, typename Func &gt;
auto run(T&amp;&amp; val, Func f) -&gt; decltype(f(std::forward&lt;T&gt;(val))) { return f(std::forward&lt;T&gt;(val)); }
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2405167</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405167</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 23 Jun 2014 10:34:06 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 11:34:54 GMT]]></title><description><![CDATA[<p>kurze_frage_atwork schrieb:</p>
<blockquote>
<p>mein Problem</p>
</blockquote>
<p>Wo kommt sowas denn vor?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2405182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405182</guid><dc:creator><![CDATA[kkaw]]></dc:creator><pubDate>Mon, 23 Jun 2014 11:34:54 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 11:59:28 GMT]]></title><description><![CDATA[<p>kkaw schrieb:</p>
<blockquote>
<p>kurze_frage_atwork schrieb:</p>
<blockquote>
<p>mein Problem</p>
</blockquote>
<p>Wo kommt sowas denn vor?</p>
</blockquote>
<p>Vergiss es. Hatte einen Knoten im Kopf. Das einzig komplizierte dran ist der Returntyp. Dafür kann man <code>decltype</code> und ggf auch <code>declval</code> verwenden, wie es Arcoth zeigte. Für Funksionsaufrufe als Ausdrücke gibt es allerdings extra ein type trait: result_of</p>
<pre><code class="language-cpp">#include &lt;type_traits&gt;

template&lt;class T, class F&gt;
typename std::result_of&lt;F(T)&gt;::type run(T val, F f)
{
   return fun(val);
}
</code></pre>
<p>In C++11 würde ich das aber vermeiden, weil es nicht &quot;SFINAE-kompatibel&quot; ist und das <code>typename</code> ... <code>type</code> nervt da auch etwas.</p>
<p>Ab C++14 sieht das aber besser aus:</p>
<pre><code class="language-cpp">#include &lt;type_traits&gt;

template&lt;class T, class F&gt;
std::result_of_t&lt;F(T)&gt; run(T val, F f)
{
   return fun(val);
}
</code></pre>
<p>Bzgl SFINAE ist das auch so in Ordnung ab C++14.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2405186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405186</guid><dc:creator><![CDATA[kkaw]]></dc:creator><pubDate>Mon, 23 Jun 2014 11:59:28 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 12:08:35 GMT]]></title><description><![CDATA[<p>Den Rückgabetyp kann man in C++14 einfacher angeben:</p>
<pre><code class="language-cpp">#include &lt;type_traits&gt;

template&lt;class T, class F&gt;
decltype(auto) run(T val, F f)
{
   return fun(val);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2405190</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405190</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Mon, 23 Jun 2014 12:08:35 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 12:13:01 GMT]]></title><description><![CDATA[<p>@kkaw: Seit C++14 haben wir placeholder-Typen als Rückgabetypen ohne trailing-return-type, wozu <code>result_of</code> ? Dass ersteres kein SFINAE unterstützt, ist nicht so schlimm.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2405191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405191</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 23 Jun 2014 12:13:01 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 12:42:15 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Den Rückgabetyp kann man in C++14 einfacher angeben:</p>
<pre><code class="language-cpp">decltype(auto)
</code></pre>
</blockquote>
<p>Ja stimmt. Hatte ich verdrängt. Wisst ihr denn auch, wie das mit SFINAE zusammenspielt? Ich hatte da noch nicht drüber nachgedacht/es nachgeguckt.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Dass ersteres kein SFINAE unterstützt, ist nicht so schlimm.</p>
</blockquote>
<p>Hätte ich die SFINAE Sache nicht erwähnt, hättest Du mich bestimmt drauf aufmerksam machen wollen. <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/2405205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405205</guid><dc:creator><![CDATA[kkaw]]></dc:creator><pubDate>Mon, 23 Jun 2014 12:42:15 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 12:54:33 GMT]]></title><description><![CDATA[<blockquote>
<p>Wisst ihr denn auch, wie das mit SFINAE zusammenspielt? Ich hatte da noch nicht drüber nachgedacht/es nachgeguckt.</p>
</blockquote>
<p>Da der Ausdruck der zurückgegeben wird ja im Funktionsrumpf steht, greift SFINAE nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2405214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405214</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 23 Jun 2014 12:54:33 GMT</pubDate></item><item><title><![CDATA[Reply to function -object&#x2F;pointer als template argument on Mon, 23 Jun 2014 16:40:12 GMT]]></title><description><![CDATA[<p>vielen Dank für die Antworten!</p>
<p>ich glaub das hilft mir in die richtige Richtung und ich komm weiter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2405280</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2405280</guid><dc:creator><![CDATA[kurze_frage]]></dc:creator><pubDate>Mon, 23 Jun 2014 16:40:12 GMT</pubDate></item></channel></rss>