<?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 und Typen]]></title><description><![CDATA[<p>Hi!</p>
<p>Kann man bei einer Template-Funktion durch irgendwelche Tricks erkennen, was für Typen übergeben wurden? Also ob POT, Non-POT, Zeiger, oder sonstwas?<br />
Ich meine sowas schonmal gesehen zu haben, zumindest für (Funktions-?)Zeiger. Ich find im großen weiten Internet aber nichts <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
<p>Dankbar für jede Antwort,<br />
ergebendst,<br />
Badestrand</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/186741/templates-und-typen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 10:20:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/186741.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Jul 2007 21:50:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 21:50:40 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Kann man bei einer Template-Funktion durch irgendwelche Tricks erkennen, was für Typen übergeben wurden? Also ob POT, Non-POT, Zeiger, oder sonstwas?<br />
Ich meine sowas schonmal gesehen zu haben, zumindest für (Funktions-?)Zeiger. Ich find im großen weiten Internet aber nichts <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
<p>Dankbar für jede Antwort,<br />
ergebendst,<br />
Badestrand</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323449</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323449</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Wed, 11 Jul 2007 21:50:40 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:02:49 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;class T&gt;
struct IsPointer
{
    enum { result = false };
};

template&lt;class T&gt;
struct IsPointer&lt;T*&gt;
{
    enum { result = true };
};

template&lt;class T&gt;
struct IsConst
{
    enum { result = false };
};

template&lt;class T&gt;
struct IsConst&lt;const T&gt;
{
    enum { result = true };
}

...
</code></pre>
<p>Für PODs fällt mir nix ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323456</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:02:49 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:04:09 GMT]]></title><description><![CDATA[<p>ui, das ist tricky <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="🙂"
    /> Danke dir!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323457</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:04:09 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:31:13 GMT]]></title><description><![CDATA[<p>Maybe für POD's das hier:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
struct IsInt {

    enum { result = false };
};

template&lt;class T&gt;
struct IsDouble {

    enum { result = false };
};

template&lt;&gt;
struct IsInt&lt;int&gt; {

    enum { result = true };
};

template&lt;&gt;
struct IsDouble&lt;double&gt; {

    enum { result = true };
};
</code></pre>
<p>Inspiriert von Michael's Code ist mir das eingefallen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323459</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:32:09 GMT]]></title><description><![CDATA[<p>hola</p>
<pre><code class="language-cpp">template&lt;class T&gt;
inline bool is_pointer_type(T value)
{
   return false;
}

template&lt;class T&gt;
inline bool is_pointer_type(T *value)
{
   return true;
}

template&lt;class T&gt;
inline bool IsPod(T&amp;)
{
   return type_traits&lt;T&gt;::is_pod;
}

template&lt;class T&gt;
struct type_traits
{
   static const bool is_pod     = false;
   static const bool is_integer = false;
   static const bool is_real    = false;
   static const bool is_signed  = false;
};

template&lt;&gt;
struct type_traits&lt;char&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = true;
   typedef signed char signed_t;
   typedef unsigned char unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;unsigned char&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = false;
   typedef signed char signed_t;
   typedef unsigned char unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;short&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = true;
   typedef short signed_t;
   typedef unsigned short unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;unsigned short&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = false;
   typedef unsigned short signed_t;
   typedef unsigned short unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;int&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = true;
   typedef int signed_t;
   typedef unsigned int unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;unsigned int&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = false;
   typedef int signed_t;
   typedef unsigned int unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;long long int&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = true;
   typedef long long int signed_t;
   typedef unsigned long long int unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;unsigned long long int&gt;
{
   static const bool is_pod     = true;
   static const bool is_integer = true;
   static const bool is_real    = false;
   static const bool is_signed  = false;
   typedef long long int signed_t;
   typedef unsigned long long int unsigned_t;
};

template&lt;&gt;
struct type_traits&lt;float&gt;
{
   static const bool is_pod = true;
   static const bool is_integer = false;
   static const bool is_real = true;
   static const bool is_signed = true;
};

template&lt;&gt;
struct type_traits&lt;double&gt;
{
   static const bool is_pod = true;
   static const bool is_integer = false;
   static const bool is_real = true;
   static const bool is_signed = true;
};

template&lt;&gt;
struct type_traits&lt;bool&gt;
{
   static const bool is_pod = true;
   static const bool is_integer = true;
   static const bool is_real = false;
   static const bool is_signed = false;
};
</code></pre>
<p>hab ich mir mal zusammengeschrieben, fuer ne BinaryStream klasse.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323460</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:32:09 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:34:22 GMT]]></title><description><![CDATA[<p>Boost.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323461</guid><dc:creator><![CDATA[Mr. N]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:34:22 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:34:58 GMT]]></title><description><![CDATA[<p>Das sieht gut aus Meep Meep <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="🙂"
    /><br />
Wollte auch gerade editieren und Trait-Klassen vorschlagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323462</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:34:58 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:37:37 GMT]]></title><description><![CDATA[<p><a href="http://www.boost.org/libs/type_traits/index.html" rel="nofollow">http://www.boost.org/libs/type_traits/index.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323464</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323464</guid><dc:creator><![CDATA[Mr. N]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:37:37 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:39:18 GMT]]></title><description><![CDATA[<p>Mr. N schrieb:</p>
<blockquote>
<p><a href="http://www.boost.org/libs/type_traits/index.html" rel="nofollow">http://www.boost.org/libs/type_traits/index.html</a></p>
</blockquote>
<p>Wir bauen uns selber eine Sandburg :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323465</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:39:18 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Wed, 11 Jul 2007 22:40:36 GMT]]></title><description><![CDATA[<p>Hallo,<br />
die Variante mit der expliziten Aufzälung ist für PODs etwas schlecht, da es beliebig viele POD-Typen gibt. Dummerweise lässt sich ein is_pod&lt;T&gt; in Standard-C++ nicht vollständig implementieren. Um wirklich für jedes T definitiv entscheiden zu können, ob es ein POD-Typ ist oder nicht, bedarf es der Mithilfe vom Compiler.</p>
<p>Eine sehr gut Type-Traits-Library, die alle deine gestellten Fragen beantworten kann, findest du in den boost-Libs (<a href="http://www.boost.org/doc/html/boost_typetraits.html" rel="nofollow">http://www.boost.org/doc/html/boost_typetraits.html</a>).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323466</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Wed, 11 Jul 2007 22:40:36 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Thu, 12 Jul 2007 05:37:17 GMT]]></title><description><![CDATA[<p>Und was is mit const, volatile und const volatile Zeigern? <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>
<pre><code class="language-cpp">template&lt; typename T &gt;
struct is_pointer&lt; T* const &gt;
{
	enum { value = true };
};

template&lt; typename T &gt;
struct is_pointer&lt; T* volatile &gt;
{
	enum { value = true };
};

template&lt; typename T &gt;
struct is_pointer&lt; T* const volatile &gt;
{
	enum { value = true };
};
</code></pre>
<p>Microsoft bietet übrigens einige Typetrait funktionen an, z.B. __is_pod(): <a href="http://msdn2.microsoft.com/en-us/library/ms177194(VS.80).aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms177194(VS.80).aspx</a></p>
<p>Achja, wo wir grad beim sammeln sind! <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>
<pre><code class="language-cpp">template&lt; typename T1, typename T2 &gt;
struct is_same
{
	enum { value = false };
};

template&lt; typename T &gt;
struct is_same&lt; T, T &gt;
{
	enum { value = true };
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1323504</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323504</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Thu, 12 Jul 2007 05:37:17 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Thu, 12 Jul 2007 05:56:24 GMT]]></title><description><![CDATA[<p>Gibt es irgendeinen Grund, dass ihr alle noch den 'enum'-Hack verwendet, um den Wert zu definieren? Was spricht bei heutigen Compilern gegen folgenden Code?</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
struct is_… {
    static bool const value = false;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1323519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323519</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Thu, 12 Jul 2007 05:56:24 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Thu, 12 Jul 2007 05:59:28 GMT]]></title><description><![CDATA[<p>Garnichts, aber was spricht gegen den enum-hack? <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1323521</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323521</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Thu, 12 Jul 2007 05:59:28 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Thu, 12 Jul 2007 06:22:09 GMT]]></title><description><![CDATA[<p>David_pb schrieb:</p>
<blockquote>
<p>Garnichts, aber was spricht gegen den enum-hack? <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>
</blockquote>
<ul>
<li>Er sieht &quot;hässlich&quot; aus</li>
<li>Er versteckt die wahre Semantik des Codes</li>
<li>Er verwendet einen falschen Typ (enum/int) statt bool</li>
<li>Er braucht zusätzliche geschweifte Klammern, die man auf einer deutschen PC-Tastatur schlecht erreicht (interessiert mich nicht, ich verwende nen Mac)</li>
</ul>
<p>Keine schwerwiegenden Gründe (bis auf den zweiten Punkt), aber doch alles in allem Gründe genug für mich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323533</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Thu, 12 Jul 2007 06:22:09 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Thu, 12 Jul 2007 06:28:49 GMT]]></title><description><![CDATA[<p>HumeSikkins schrieb:</p>
<blockquote>
<p>Hallo,<br />
die Variante mit der expliziten Aufzälung ist für PODs etwas schlecht, da es beliebig viele POD-Typen gibt. Dummerweise lässt sich ein is_pod&lt;T&gt; in Standard-C++ nicht vollständig implementieren.</p>
</blockquote>
<p>werden dann klassen und strukturen die aus reinen pods bestehen auch als pod gewerted ? oder wie ist das zu verstehen ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323535</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Thu, 12 Jul 2007 06:28:49 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Typen on Thu, 12 Jul 2007 06:31:13 GMT]]></title><description><![CDATA[<p>Naja, die Punkte 1 und 4 find ich nich soo überzeugend, aber 2 und 3 haben was! <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>Meep Meep schrieb:</p>
<blockquote>
<p>HumeSikkins schrieb:</p>
<blockquote>
<p>Hallo,<br />
die Variante mit der expliziten Aufzälung ist für PODs etwas schlecht, da es beliebig viele POD-Typen gibt. Dummerweise lässt sich ein is_pod&lt;T&gt; in Standard-C++ nicht vollständig implementieren.</p>
</blockquote>
<p>werden dann klassen und strukturen die aus reinen pods bestehen auch als pod gewerted ? oder wie ist das zu verstehen ?</p>
<p>Meep Meep</p>
</blockquote>
<p>Ja. Siehe: <a href="http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7" rel="nofollow">http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1323536</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1323536</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Thu, 12 Jul 2007 06:31:13 GMT</pubDate></item></channel></rss>