<?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[Partial specialization of template function]]></title><description><![CDATA[<p>How to make it?</p>
<p>This does not works:</p>
<pre><code class="language-cpp">template&lt;int N, class T&gt; inline T CalculateDeterminant(cMatrix&lt;N,N,T&gt; &amp;m)
{
    [ The code that calls CalculateDeterminant(cMatrix&lt;N-1,N-1,T&gt;) ]
}

template&lt;class T&gt; inline T CalculateDeterminant&lt;1&gt;(cMatrix&lt;1,1,T&gt; &amp;m)
{
    return m.FirstVector().FirstElement();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/204944/partial-specialization-of-template-function</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 22:04:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/204944.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Feb 2008 14:06:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 14:25:16 GMT]]></title><description><![CDATA[<p>How to make it?</p>
<p>This does not works:</p>
<pre><code class="language-cpp">template&lt;int N, class T&gt; inline T CalculateDeterminant(cMatrix&lt;N,N,T&gt; &amp;m)
{
    [ The code that calls CalculateDeterminant(cMatrix&lt;N-1,N-1,T&gt;) ]
}

template&lt;class T&gt; inline T CalculateDeterminant&lt;1&gt;(cMatrix&lt;1,1,T&gt; &amp;m)
{
    return m.FirstVector().FirstElement();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1451996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1451996</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Fri, 08 Feb 2008 14:25:16 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 14:14:47 GMT]]></title><description><![CDATA[<p>template&lt;1, class T&gt; inline T CalculateDeterminant&lt;1&gt;(cMatrix&lt;1,1,T&gt; &amp;m)<br />
{<br />
return m.FirstVector().FirstElement();<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1451999</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1451999</guid><dc:creator><![CDATA[try_this]]></dc:creator><pubDate>Fri, 08 Feb 2008 14:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 14:24:06 GMT]]></title><description><![CDATA[<p><strong>try_this</strong>, it does not works too.</p>
<p>I used function overload instead:</p>
<pre><code class="language-cpp">template&lt;int N, class T&gt; inline T CalculateDeterminant(cMatrix&lt;N,N,T&gt; &amp;m)
{
    [ The code that calls CalculateDeterminant(cMatrix&lt;N-1,N-1,T&gt;) ]
}

template&lt;class T&gt; inline T CalculateDeterminant(cMatrix&lt;1,1,T&gt; &amp;m)
{
    return m.FirstVector().FirstElement();
}
</code></pre>
<p>What is the difference between overload and template specialization?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452004</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452004</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Fri, 08 Feb 2008 14:24:06 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 14:31:59 GMT]]></title><description><![CDATA[<p>try this:<br />
[cpp]<br />
template&lt;class T&gt; inline T CalculateDeterminant&lt;1**,T**&gt;(cMatrix&lt;1,1,T&gt; &amp;m)<br />
{<br />
return m.FirstVector().FirstElement();<br />
}[/cpp]</p>
<p>What is the difference between overload and template specialization?<br />
Well overloading is just that overloading (same method but different parameter list) and specialization is a version of a template function which is more restrictive concerning its template parameters.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452011</guid><dc:creator><![CDATA[lolz_ausgeloggt]]></dc:creator><pubDate>Fri, 08 Feb 2008 14:31:59 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 14:45:05 GMT]]></title><description><![CDATA[<p>Ahem, guys, you <strong>do</strong> know that function templates cannot be specialized <em>partially</em>, do you? Neither try_this' nor lolz' solution are allowed in standard C++. The only thing you can do is a full template specialization - and you better do not, because the specialization does not participate in overload resolution. Use overloading instead.</p>
<p>The overloading SAn uses is the right way.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452020</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452020</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Fri, 08 Feb 2008 14:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 15:02:05 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>The only thing you can do is a full template specialization - and you better do not, because the specialization does not participate in overload resolution.</p>
</blockquote>
<p>Which may actually be what's intended. Anyway, it is always possible to defer a function template to a class template und thus gain the benefit of partial specializations. Depending on the complexity this can be preferable to overloading since overloading does more easily (and subtly) result in ambiguities.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452035</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 08 Feb 2008 15:02:05 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 15:10:10 GMT]]></title><description><![CDATA[<p>What does it mean: “the specialization does not participate in overload resolution” ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452039</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Fri, 08 Feb 2008 15:10:10 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 15:13:44 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>... it is always possible to defer a function template to a class template und thus gain the benefit of partial specializations. ...</p>
</blockquote>
<p>Hm... Is it possible to make <code>static operator()</code> in the class, so I can “call class like function”?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452043</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Fri, 08 Feb 2008 15:13:44 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 15:22:52 GMT]]></title><description><![CDATA[<p>SAn schrieb:</p>
<blockquote>
<p>camper schrieb:</p>
<blockquote>
<p>... it is always possible to defer a function template to a class template und thus gain the benefit of partial specializations. ...</p>
</blockquote>
<p>Hm... Is it possible to make <code>static operator()</code> in the class, so I can “call class like function”?</p>
</blockquote>
<p>No, member functions used for operator overloading must always be non-static (except for new/new[]/delete/delete[]). But since it's an implementation detail, there is no disadvantage in using a normal member function (static or not), or that class template could model a function object (which may as well be part of the interface to be used with standard algorithms).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452050</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452050</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 08 Feb 2008 15:22:52 GMT</pubDate></item><item><title><![CDATA[Reply to Partial specialization of template function on Fri, 08 Feb 2008 16:08:42 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;class T,int N&gt; class Matrix
{
public:
  Matrix():ele(N){};
  T ele;
};

template&lt;class T,int N&gt; T Calc(Matrix&lt;T,N&gt;&amp; r)
{
  return Calc(Matrix&lt;T,N-1&gt;());  
};

template&lt;class T&gt; T Calc(Matrix&lt;T,1&gt;&amp; r)
{ 
  return r.ele;
};

void test()
{
  Matrix&lt;double,3&gt; m; 
  double ele;

  ele=Calc(m);
}
</code></pre>
<p>sometimes it make sense.<br />
The last call is</p>
<pre><code class="language-cpp">template&lt;class T&gt; T Calc(Matrix&lt;T,1&gt;&amp; r)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1452083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452083</guid><dc:creator><![CDATA[idefix]]></dc:creator><pubDate>Fri, 08 Feb 2008 16:08:42 GMT</pubDate></item></channel></rss>