<?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[templates einschränken]]></title><description><![CDATA[<p>hi<br />
kann man (wenn ja wie kann man) bei einem template die variablen einschränken?</p>
<p>bsp:</p>
<pre><code>template&lt;class T&gt; 
void foo(T t);//hier soll T z.b. nur gleich einem primitiven datentyp sein

class asdf;
template&lt;class T&gt; 
void foo(T t);//hier soll T nur asdf oder eine abgeleitete klasse sein.
</code></pre>
<p>schonmal danke für antworten</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/294315/templates-einschränken</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 22:38:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/294315.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Oct 2011 19:40:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to templates einschränken on Sat, 22 Oct 2011 19:40:52 GMT]]></title><description><![CDATA[<p>hi<br />
kann man (wenn ja wie kann man) bei einem template die variablen einschränken?</p>
<p>bsp:</p>
<pre><code>template&lt;class T&gt; 
void foo(T t);//hier soll T z.b. nur gleich einem primitiven datentyp sein

class asdf;
template&lt;class T&gt; 
void foo(T t);//hier soll T nur asdf oder eine abgeleitete klasse sein.
</code></pre>
<p>schonmal danke für antworten</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134456</guid><dc:creator><![CDATA[templatefrage]]></dc:creator><pubDate>Sat, 22 Oct 2011 19:40:52 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sat, 22 Oct 2011 19:43:44 GMT]]></title><description><![CDATA[<p>Google mal nach boost::enable_if.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134457</guid><dc:creator><![CDATA[templateantwort]]></dc:creator><pubDate>Sat, 22 Oct 2011 19:43:44 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sat, 22 Oct 2011 19:45:01 GMT]]></title><description><![CDATA[<p>Beitrag zu einem ähnlichen Thema:<br />
<a href="http://www.c-plusplus.net/forum/p1978346#1978346" rel="nofollow">http://www.c-plusplus.net/forum/p1978346#1978346</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134458</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sat, 22 Oct 2011 19:45:01 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sat, 22 Oct 2011 19:56:18 GMT]]></title><description><![CDATA[<p>Das ist so ein Thema bei dem ich finde, dass C++ keine zufriedenstellende Lösung anbietet. Eine Möglichkeit wäre z.B. Gefrickel mit std::is_same.<br />
@Alle die jetzt sagen, der Compiler gibt doch eh einen Fehler: Ja, wahrscheinlich schon, aber meistens einen unlesbaren.<br />
Ich habe irgendwann mal etwas über Concepts gehört, da konnte man definieren, welche Konzepte ein Typ mitbringen muss. Bin mir jetzt aber gerade nicht sicher, ob das überhaupt in den Standard gesteckt wurde.. Edit: Tja.. <a href="http://en.wikipedia.org/wiki/Concepts_%28C%2B%2B%29" rel="nofollow">http://en.wikipedia.org/wiki/Concepts_(C%2B%2B)</a> oO</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134463</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 22 Oct 2011 19:56:18 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sat, 22 Oct 2011 20:56:31 GMT]]></title><description><![CDATA[<p>Wenn du es einschränken musst, würd ich mir mal überlegen, ob das wirklich ein template sein sollte. Warum dürfen es nur primitive Typen sein? Was spricht dagegen z.B. einen std::complex durchzuschicken?<br />
Im Fall von &quot;nur asdf oder abgeleitete Klasse&quot; würd ich auch jeden Fall mal meinen, dass du eigentlich kein template, sondern eine normale Funktion haben willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134481</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Sat, 22 Oct 2011 20:56:31 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sat, 22 Oct 2011 21:03:25 GMT]]></title><description><![CDATA[<p>templatefrage schrieb:</p>
<blockquote>
<pre><code>class asdf;
template&lt;class T&gt; 
void foo(T t);//hier soll T nur asdf oder eine abgeleitete klasse sein.
</code></pre>
</blockquote>
<p>Na, dann machen wir doch einfach</p>
<pre><code class="language-cpp">void foo(asdf&amp; t);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2134484</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134484</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Sat, 22 Oct 2011 21:03:25 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sun, 23 Oct 2011 09:41:42 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void foo(asdf* t);
</code></pre>
<p>heißen ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134606</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134606</guid><dc:creator><![CDATA[Muss das nicht]]></dc:creator><pubDate>Sun, 23 Oct 2011 09:41:42 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sun, 23 Oct 2011 09:49:05 GMT]]></title><description><![CDATA[<p>wieso?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134612</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Sun, 23 Oct 2011 09:49:05 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sun, 23 Oct 2011 09:56:07 GMT]]></title><description><![CDATA[<p>Wenn es im Kontext Sinn macht, einen Nullzeiger übergeben zu dürfen, okay. Ansonsten würde ich die Referenz vorziehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134614</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 23 Oct 2011 09:56:07 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sun, 23 Oct 2011 12:05:42 GMT]]></title><description><![CDATA[<p>Zur Beschränkung auf primitive typen:<br />
Wie wärs mit</p>
<pre><code class="language-cpp">template&lt;class T&gt; 
void foo(T t) //hier soll T z.b. nur gleich einem primitiven datentyp sein
{
  static_assert(Loki::TypeTraits&lt;T&gt;::isFundamental, &quot;T ist kein primitiver Typ&quot;);
}
</code></pre>
<p>Musst dir dann nur eben loki ziehen. Für diese Sachen wirst du denke ich mit header only auskommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134690</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134690</guid><dc:creator><![CDATA[*Q* 1]]></dc:creator><pubDate>Sun, 23 Oct 2011 12:05:42 GMT</pubDate></item><item><title><![CDATA[Reply to templates einschränken on Sun, 23 Oct 2011 13:41:48 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Ich habe irgendwann mal etwas über Concepts gehört, da konnte man definieren, welche Konzepte ein Typ mitbringen muss. Bin mir jetzt aber gerade nicht sicher, ob das überhaupt in den Standard gesteckt wurde..</p>
</blockquote>
<p>Wurde von C++11 wieder entfernt, weil zu unausgereift. Mir gefällt an den Concepts nicht, dass bisher oft die Fehlerlesbarkeit als Hauptargument angeführt wurde. Das ist meiner Meinung nach nicht Rechtfertigung genug für ein neues, derart komplexes Sprachmittel. Ich habe mich aber auch nie ausführlich mit Concepts befasst, nicht zuletzt, weil sie – wenn überhaupt – erst in ferner Zukunft relevant werden.</p>
<p>Q schrieb:</p>
<blockquote>
<p>Musst dir dann nur eben loki ziehen.</p>
</blockquote>
<p>Nein, C++11 hat Type Traits und damit auch <code>std::is_fundamental</code> .</p>
<p>Aber dot hat schon Recht, man muss einen guten Grund haben, um die Generizität einzuschränken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134742</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 23 Oct 2011 13:41:48 GMT</pubDate></item></channel></rss>