<?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[Ist das eine gute Lösung, um fehlende partielle Spezialisierung von Funktions-Templates zu kompensieren?]]></title><description><![CDATA[<p>Hallo!</p>
<p>C++ unterstützt ja leider keine partielle Spezialisierung von Funktions-Templates. Also ich würde gern folgendes machen, nur als Beispiel:</p>
<pre><code class="language-cpp">template&lt;int A, int B&gt; int add()
{
    return A + B;
}

// partielle Spezialisierung - geht nicht!
template&lt;int X&gt; int add&lt;X, -X&gt;()
{
    return 0;
}
</code></pre>
<p>Natürlich ist das Blödsinn, ist nur um die Situation zu beschreiben.<br />
Ich mach es jetzt so:</p>
<pre><code class="language-cpp">template&lt;int A, int B&gt; struct AddHelper
{
    static int add()
    {
        return A + B;
    }
};

// Spezialisierung
template&lt;int X&gt; struct AddHelper&lt;X, -X&gt;
{
    static int add()
    {
        return 0;
    }
};

// &quot;Delegate&quot;
template&lt;int A, int B&gt; int add()
{
    return AddHelper&lt;A, B&gt;::add();
}
</code></pre>
<p>Gibt es eine andere/bessere Lösung für sowas?<br />
Ist das &quot;guter Stil&quot;, oder wird man dafür hingerichtet?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/174454/ist-das-eine-gute-lösung-um-fehlende-partielle-spezialisierung-von-funktions-templates-zu-kompensieren</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 20:17:09 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174454.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Feb 2007 14:21:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ist das eine gute Lösung, um fehlende partielle Spezialisierung von Funktions-Templates zu kompensieren? on Tue, 27 Feb 2007 14:21:45 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>C++ unterstützt ja leider keine partielle Spezialisierung von Funktions-Templates. Also ich würde gern folgendes machen, nur als Beispiel:</p>
<pre><code class="language-cpp">template&lt;int A, int B&gt; int add()
{
    return A + B;
}

// partielle Spezialisierung - geht nicht!
template&lt;int X&gt; int add&lt;X, -X&gt;()
{
    return 0;
}
</code></pre>
<p>Natürlich ist das Blödsinn, ist nur um die Situation zu beschreiben.<br />
Ich mach es jetzt so:</p>
<pre><code class="language-cpp">template&lt;int A, int B&gt; struct AddHelper
{
    static int add()
    {
        return A + B;
    }
};

// Spezialisierung
template&lt;int X&gt; struct AddHelper&lt;X, -X&gt;
{
    static int add()
    {
        return 0;
    }
};

// &quot;Delegate&quot;
template&lt;int A, int B&gt; int add()
{
    return AddHelper&lt;A, B&gt;::add();
}
</code></pre>
<p>Gibt es eine andere/bessere Lösung für sowas?<br />
Ist das &quot;guter Stil&quot;, oder wird man dafür hingerichtet?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236217</guid><dc:creator><![CDATA[VerunsicherterTyp]]></dc:creator><pubDate>Tue, 27 Feb 2007 14:21:45 GMT</pubDate></item><item><title><![CDATA[Reply to Ist das eine gute Lösung, um fehlende partielle Spezialisierung von Funktions-Templates zu kompensieren? on Tue, 27 Feb 2007 17:42:01 GMT]]></title><description><![CDATA[<p>Ich würde sagen dass das die Standardlösung (tm) ist.<br />
Hab' ich auf jeden Fall schon öfter mal gesehen, und selbst schon angewendet.</p>
<p>Geht natürlich nur wenn die Signatur der template Funktion immer gleich ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236323</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236323</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:42:01 GMT</pubDate></item></channel></rss>