<?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[Specialization by the function type]]></title><description><![CDATA[<p>Please help to understand the following</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

template&lt;class F&gt; struct function_caller;

template&lt;class R, class P1, class P2&gt; struct function_caller&lt;R (P1, P2)&gt;
{
};

int main()
{
	typedef function_caller&lt;void (int, char)&gt; my_caller;
	std::cout &lt;&lt; typeid(my_caller).name() &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<p>The program output:</p>
<pre><code>struct function_caller&lt;void __cdecl(int,char)&gt;
</code></pre>
<p>Where I can read about specialization by the function types (in English) ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/201136/specialization-by-the-function-type</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 11:57:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/201136.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Dec 2007 08:06:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Specialization by the function type on Tue, 25 Dec 2007 08:10:19 GMT]]></title><description><![CDATA[<p>Please help to understand the following</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

template&lt;class F&gt; struct function_caller;

template&lt;class R, class P1, class P2&gt; struct function_caller&lt;R (P1, P2)&gt;
{
};

int main()
{
	typedef function_caller&lt;void (int, char)&gt; my_caller;
	std::cout &lt;&lt; typeid(my_caller).name() &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<p>The program output:</p>
<pre><code>struct function_caller&lt;void __cdecl(int,char)&gt;
</code></pre>
<p>Where I can read about specialization by the function types (in English) ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1425814</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1425814</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Tue, 25 Dec 2007 08:10:19 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Fri, 04 Jan 2008 14:44:41 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>I hope your still waiting for an answer.</p>
<p>First of all the Output of</p>
<pre><code class="language-cpp">typeid().name()
</code></pre>
<p>is compiler specific, if you didn't know that. For example my compile (gcc 4.1.1) gives me</p>
<pre><code>15function_callerIFvicEE
</code></pre>
<p>as output.</p>
<p>I don't know any resources for template specialization specifically for function types.</p>
<p>What you do is a partial template specialization to get your template code to work with function types as template parameters while extracting Informations about return and argument types of the function. And that's a little bit tricky as you can see in your code.</p>
<p>If you have more questions or if I need to describe it more detailed just ask for it <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>
<p>And for your english resources (not everything might seem useful at first):<br />
<a href="http://www.parashift.com/c++-faq-lite/index.html" rel="nofollow">http://www.parashift.com/c++-faq-lite/index.html</a><br />
<a href="http://www.decadentplace.org.uk/womble/c++/template-faq.html" rel="nofollow">http://www.decadentplace.org.uk/womble/c++/template-faq.html</a><br />
<a href="http://www.tutok.sk/fastgl/callback.html" rel="nofollow">http://www.tutok.sk/fastgl/callback.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1430652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1430652</guid><dc:creator><![CDATA[Kohma]]></dc:creator><pubDate>Fri, 04 Jan 2008 14:44:41 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Tue, 22 Jan 2008 12:12:11 GMT]]></title><description><![CDATA[<p><em>typeid().name() is compiler specific, if you didn't know that. For example my compile (gcc 4.1.1) gives me ...</em></p>
<p>My .name() is better than yours :p</p>
<p><em>If you have more questions or if I need to describe it more detailed just ask for it <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="🙂"
    /></em></p>
<p>Yes! I have questions:</p>
<ol>
<li>Why line 3 in the code is necessary?</li>
<li>Can I achieve the same result (passing a function type into template) without using the specialization technique?</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/1441229</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441229</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Tue, 22 Jan 2008 12:12:11 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Tue, 22 Jan 2008 12:09:01 GMT]]></title><description><![CDATA[<p>1. Because the function is defined AFTER the function that uses it. So otherwise the compiler wouldn't even know that it is there. It is a bit lazy and stops looking for a function when it is about to be used instead of parsing the rest of the file. This &quot;prototyping&quot; shows the compiler that there will be a function like that later on and that he shouldn't worry about it. <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/1441234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441234</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Tue, 22 Jan 2008 12:09:01 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Tue, 22 Jan 2008 12:18:59 GMT]]></title><description><![CDATA[<p><strong>Fellhuhn</strong> I know what is prototyping. But im my code there is no prototyping. It is a &quot;template specialization&quot;.</p>
<p>IMHO.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441238</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Tue, 22 Jan 2008 12:18:59 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Tue, 22 Jan 2008 12:22:26 GMT]]></title><description><![CDATA[<p>It is a declaration of the template itself. Because if there is no template &quot;function_caller&quot;, there can't be any specialization of &quot;function_caller&quot;. And to let the compiler know that there is (at least let him assume there is), you declare it before specializing it.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441240</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441240</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 22 Jan 2008 12:22:26 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Tue, 22 Jan 2008 12:25:47 GMT]]></title><description><![CDATA[<p><strong>LordJaxom</strong>. OK, thank you. What about my question #2 ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441242</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Tue, 22 Jan 2008 12:25:47 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Tue, 22 Jan 2008 12:53:03 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;

template&lt;class F&gt; struct function_caller;

template&lt;class R, class P1, class P2&gt; struct function_caller&lt;R (P1, P2)&gt;
{
};

int main()
{
    typedef function_caller&lt;void (int, char)&gt; my_caller;
    std::cout &lt;&lt; typeid(my_caller).name() &lt;&lt; std::endl;

    return 0;
}
</code></pre>
<p>SAn schrieb:</p>
<blockquote>
<p>Can I achieve the same result (passing a function type into template) without using the specialization technique?</p>
</blockquote>
<p>yes, you can:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

template&lt;class F&gt; struct function_caller
{
};

int main()
{
    typedef function_caller&lt;void (int, char)&gt; my_caller;
    std::cout &lt;&lt; typeid(my_caller).name() &lt;&lt; std::endl;

    return 0;
}
</code></pre>
<p>the first declaration of function_caller only tells the compiler that it has one template parameter. and <code>void (int,char)</code> is not a compound, but one distinct type (which is used as a template argument in this example)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441257</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Tue, 22 Jan 2008 12:53:03 GMT</pubDate></item><item><title><![CDATA[Reply to Specialization by the function type on Tue, 22 Jan 2008 14:37:00 GMT]]></title><description><![CDATA[<p>queer_boy schrieb:</p>
<blockquote>
<p>...the first declaration of function_caller only tells the compiler that it has one template parameter. and <code>void (int,char)</code> is not a compound, but one distinct type (which is used as a template argument in this example)</p>
</blockquote>
<p>Hmm... <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="🙄"
    /><br />
Thank you.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441336</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Tue, 22 Jan 2008 14:37:00 GMT</pubDate></item></channel></rss>