<?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[Teilspezialisierung von Funktions-Templates]]></title><description><![CDATA[<p>Abend.</p>
<pre><code class="language-cpp">//Funktions-Template
template&lt; int N, class T &gt;
void test()
{
}

//Spezialisierung 1
template&lt; &gt;
void test&lt; 3, float&gt;()
{
}
</code></pre>
<p>Soweit funktioniert das ja ganz gut. Bekomme ich jetzt auch irgendwie eine Teilspezialisierung t&lt; 3, T[variabel] &gt; hin?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/194677/teilspezialisierung-von-funktions-templates</link><generator>RSS for Node</generator><lastBuildDate>Tue, 29 Sep 2026 15:56:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/194677.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Oct 2007 18:00:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Teilspezialisierung von Funktions-Templates on Tue, 09 Oct 2007 18:00:26 GMT]]></title><description><![CDATA[<p>Abend.</p>
<pre><code class="language-cpp">//Funktions-Template
template&lt; int N, class T &gt;
void test()
{
}

//Spezialisierung 1
template&lt; &gt;
void test&lt; 3, float&gt;()
{
}
</code></pre>
<p>Soweit funktioniert das ja ganz gut. Bekomme ich jetzt auch irgendwie eine Teilspezialisierung t&lt; 3, T[variabel] &gt; hin?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381518</guid><dc:creator><![CDATA[krabbels]]></dc:creator><pubDate>Tue, 09 Oct 2007 18:00:26 GMT</pubDate></item><item><title><![CDATA[Reply to Teilspezialisierung von Funktions-Templates on Tue, 09 Oct 2007 18:11:21 GMT]]></title><description><![CDATA[<p>krabbels schrieb:</p>
<blockquote>
<p>Abend.</p>
<pre><code class="language-cpp">//Funktions-Template
template&lt; int N, class T &gt;
void test()
{
}

//Spezialisierung 1
template&lt; &gt;
void test&lt; 3, float&gt;()
{
}
</code></pre>
<p>Soweit funktioniert das ja ganz gut. Bekomme ich jetzt auch irgendwie eine Teilspezialisierung t&lt; 3, T[variabel] &gt; hin?</p>
</blockquote>
<p>nein. Partielle Spezialisierung ist nur mit Klassentemplates möglich. Du könntest also das Funktionstemplate dazu nutzen, einen Funktor aufzurufen, und diesen dann entsprechend partiell spezialisieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381525</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 09 Oct 2007 18:11:21 GMT</pubDate></item><item><title><![CDATA[Reply to Teilspezialisierung von Funktions-Templates on Tue, 09 Oct 2007 18:19:29 GMT]]></title><description><![CDATA[<p>Auch sehr häufig sieht man die Methode aus &quot;Modernes C++ Design&quot; (k.A. wo es erfunden wurde):</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
struct type2type
{
    typedef T type;
};

template &lt;typename T&gt;
void do_something (T const&amp; p)
{
    do_something (type2type&lt;T&gt; (), p);
}

void do_something (type2type&lt;double&gt;, double param);

void do_something (type2type&lt;int&gt;, int param);
</code></pre>
<p>Ist letztlich aber dasselbe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381530</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Tue, 09 Oct 2007 18:19:29 GMT</pubDate></item><item><title><![CDATA[Reply to Teilspezialisierung von Funktions-Templates on Wed, 10 Oct 2007 08:17:31 GMT]]></title><description><![CDATA[<p>.filmor schrieb:</p>
<blockquote>
<p>Auch sehr häufig sieht man die Methode aus &quot;Modernes C++ Design&quot; (k.A. wo es erfunden wurde):...</p>
</blockquote>
<p>Sorry, magst Du das kurz erläutern ?<br />
Ich verstehe nicht, was es mit der 2Parameter-version von do_something() auf sich hat ....</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381785</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Wed, 10 Oct 2007 08:17:31 GMT</pubDate></item><item><title><![CDATA[Reply to Teilspezialisierung von Funktions-Templates on Wed, 10 Oct 2007 08:27:13 GMT]]></title><description><![CDATA[<p>Könnte man nicht auch einfach eine statische Methode einer Klasse benutzen (die man ja partiell spezialisieren kann)?</p>
<pre><code class="language-cpp">//Funktions-Template
template&lt;int N, class T&gt;
class Wrapper
{
    public:
    static void test()
    {
    }
};

//Spezialisierung
template&lt;class T&gt;
class Wrapper&lt;3, T&gt;
{
    static void test()
    {
    }
}
</code></pre>
<p>Das hätte halt den Nachteil, dass bei Klassen die Template-Argumente nicht aus irgendwelchen Argumenten bestimmt werden können...</p>
<p>Die Methode von .filmor verstehe ich aber auch nicht...</p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381793</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Wed, 10 Oct 2007 08:27:13 GMT</pubDate></item><item><title><![CDATA[Reply to Teilspezialisierung von Funktions-Templates on Wed, 10 Oct 2007 09:48:37 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>Ich verstehe nicht, was es mit der 2Parameter-version von do_something() auf sich hat ....</p>
</blockquote>
<p>Das ist in etwa die Methode, die man auch bei Iterator&quot;spezialisierungen&quot; nutzt: Eine (hypothetische) Funktion advance mit zwei Parametern ruft eine zweite Funktion advance_impl auf, und übergibt ihr als dritten Funktionsparameter eine Instanz des Iteratoren-Tag. Nun überlädt man advance_impl für das allgemeinste Iterator-Tag, sowie für jedes Tag, für das man Optimierungen anbieten kann. Da beim Lookup einer Funktion die Überladung mit den am besten passenden Parametern genommen wird, wird diese dann aufgerufen.</p>
<pre><code class="language-cpp">template&lt; typename It &gt;
void advance( It&amp; it, size_t off )
{
    advance_impl( it, off, typename It::iterator_category() );
}

template&lt; typename It &gt;
void advace_impl( It&amp; it, size_t off, std::forward_iterator_tag )
{
    while (off--) ++it;
}

template&lt; typename It &gt;
void advance_impl( It&amp; it, size_t off, std::random_access_iterator_tag )
{
    it += off;
}
</code></pre>
<p>Ergänzung: Der Typ des Zusatzparameters muss natürlich nicht in einer Vererbungshierarchie stecken, das sichert hier zusätzlich nur ab, dass z.B. bidirectional Iteratoren auf die Forward-Funktion zurückfällt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381799</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 10 Oct 2007 09:48:37 GMT</pubDate></item><item><title><![CDATA[Reply to Teilspezialisierung von Funktions-Templates on Wed, 10 Oct 2007 09:11:25 GMT]]></title><description><![CDATA[<p>Phoemuex schrieb:</p>
<blockquote>
<p>...<br />
Das hätte halt den Nachteil, dass bei Klassen die Template-Argumente nicht aus irgendwelchen Argumenten bestimmt werden können...</p>
</blockquote>
<p>... aber das geht bei argumentlosen Funktionstemplates sowieso nicht. <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>
<p>Aber das bringt mich auf eine andere Idee: Wie wär's mit einen template-Member ?</p>
<pre><code class="language-cpp">template &lt;int N&gt;
struct Wrapper {
   template &lt;typename FType&gt;
   static void f(FType);
};

template &lt;&gt;
struct Wrapper&lt;3&gt; {
   template &lt;typename FType&gt;
   static void f(FType) {
      // hier &quot;3-spezifisches&quot; und FType-generelles
   }      
};
</code></pre>
<p>Damit kann man wenigstens <em>einen</em> Typen (FType) beim Aufruf automatisch bestimmen lassen...</p>
<p>LordJaxom schrieb:</p>
<blockquote>
<p>...</p>
</blockquote>
<p>Ahaaa !! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /><br />
Danke, das hatte mir noch gefehlt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /> <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>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381829</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Wed, 10 Oct 2007 09:11:25 GMT</pubDate></item></channel></rss>