<?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[Parametertyp von Templatefunktion feststellen]]></title><description><![CDATA[<p>Hi, ist es möglich festzustellen, ob der Funktionsparameter einer Templatefunktion ein Objekt/Referenz/Pointer ist? Also z.B. sowas:</p>
<p>template &lt;class TParam&gt;<br />
void MyClass&lt;TParam&gt;::MyFunction(const TParam&amp; param)<br />
{<br />
if (IsPointer(param))<br />
{<br />
}<br />
elseif (IsReference(param))<br />
{<br />
}<br />
else<br />
{<br />
}<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/316992/parametertyp-von-templatefunktion-feststellen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Jul 2026 10:31:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/316992.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 May 2013 17:34:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 17:34:18 GMT]]></title><description><![CDATA[<p>Hi, ist es möglich festzustellen, ob der Funktionsparameter einer Templatefunktion ein Objekt/Referenz/Pointer ist? Also z.B. sowas:</p>
<p>template &lt;class TParam&gt;<br />
void MyClass&lt;TParam&gt;::MyFunction(const TParam&amp; param)<br />
{<br />
if (IsPointer(param))<br />
{<br />
}<br />
elseif (IsReference(param))<br />
{<br />
}<br />
else<br />
{<br />
}<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325591</guid><dc:creator><![CDATA[Enumerator]]></dc:creator><pubDate>Thu, 23 May 2013 17:34:18 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 17:35:07 GMT]]></title><description><![CDATA[<pre><code>template &lt;class TParam&gt;
void MyClass&lt;TParam&gt;::MyFunction(const TParam&amp; param)
{
    if (IsPointer(param))
    {
    }
    elseif (IsReference(param))
    {
    }
    else
    {
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2325592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325592</guid><dc:creator><![CDATA[Enumerator]]></dc:creator><pubDate>Thu, 23 May 2013 17:35:07 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 17:39:34 GMT]]></title><description><![CDATA[<p>Wozu brauchst du denn sowas? Erscheint mir äußerst suspekt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325593</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Thu, 23 May 2013 17:39:34 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 17:54:59 GMT]]></title><description><![CDATA[<p>Es gibt in C++ (seit C++11 auch im Standard) <a href="http://en.cppreference.com/w/cpp/types" rel="nofollow">Type-Traits</a>, definiert im Header <code>&lt;type_traits&gt;</code> , mit denen geht das ganz einfach:</p>
<ul>
<li><a href="http://en.cppreference.com/w/cpp/types/is_reference" rel="nofollow"> <code>std::is_reference&lt;param&gt;::value</code> </a><br />
(Achtung! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /> <code>is_reference</code> beachtet LValue und RValue-Referenzen.</li>
<li><a href="http://en.cppreference.com/w/cpp/types/is_pointer" rel="nofollow"> <code>std::is_pointer&lt;param&gt;::value</code> </a></li>
<li><a href="http://en.cppreference.com/w/cpp/types/is_object" rel="nofollow"> <code>std::is_object&lt;param&gt;::value</code> </a><br />
Nicht wahr für Typen wie Funktionen (aber wahr für Funktions<strong>zeiger</strong>), Referenzen, usw.</li>
</ul>
<p>Allerdings - wie out schon angemerkt hat - wofür brauchst du das? Siehe in meiner Signatur das XY-Problem. Das hast du gerade.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325603</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 23 May 2013 17:54:59 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:07:18 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;class TParam&gt;
void MyClass&lt;TParam&gt;::MyFunction(TParam const* param)
{
  // Zeiger
}
template &lt;class TParam&gt;
void MyClass&lt;TParam&gt;::MyFunction(TParam const&amp; param)
{
  // Referenz
}
</code></pre>
<p>Die Suggeration vom Sohne geht erst mit static-ifs.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325609</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:07:18 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:13:01 GMT]]></title><description><![CDATA[<p>Es geht darum, dass ich nicht kopierbare Objekte habe (z.B. GUI-Controls). Also kann ich diese nicht als Objekt in einer Hashmap ablegen, sondern nur einen Pointer auf diese. In meiner generischen Hashmap-Klasse habe ich aber nun das Problem, dass ich aus den Zeigern einen Hash erzeugen können muss bzw. erkennen können muss, ob es ein Zeiger oder Objekt ist. Denn die Objekte haben alle eine GetHash-Funktion. Auf einen Zeiger kann ich diese nur leider nicht anwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325611</guid><dc:creator><![CDATA[Enumerator]]></dc:creator><pubDate>Thu, 23 May 2013 18:13:01 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:21:03 GMT]]></title><description><![CDATA[<p>Die einzige Möglichkeit die ich im Moment sehe ist die Möglichkeit der Hashmap-Klasse einen custom &quot;Comparer&quot; als Parameter zu übergeben. Ich würde dann einen &quot;PointerComparer&quot; schreiben der die Zeigers als Keys miteinander vergleicht und zudem aus einem Key auch einen Hash berechnen würde. Analog gäbe es dann für richtige Objekte einen &quot;ObjectComparer&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325614</guid><dc:creator><![CDATA[Enumerator]]></dc:creator><pubDate>Thu, 23 May 2013 18:21:03 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:21:31 GMT]]></title><description><![CDATA[<p>Auch das geht. Aber du willst auch das nicht.</p>
<p>Wenn du schon einen Pointer hast =&gt; DAS IST DEIN HASH!!! Deine Hashfunktion ist garantiert schlechter als ein Pointer, der 1. garantiert unique und 2. ohne Berechnung verfügbar ist.</p>
<p>Noch besser ist allerdings &lt;boost/unordered_map&gt; oder &lt;tr1/unordered_map&gt; oder &lt;unordered_map&gt; (C++11) einzubinden und davon zu profitieren. Da ist dein Hashproblem schon gelöst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325615</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325615</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:21:31 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:27:32 GMT]]></title><description><![CDATA[<p>deinvater schrieb:</p>
<blockquote>
<p>Die Suggeration vom Sohne geht erst mit static-ifs.</p>
</blockquote>
<p>Ähm...nein!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325617</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325617</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 23 May 2013 18:27:32 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:28:19 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>deinvater schrieb:</p>
<blockquote>
<p>Die Suggeration vom Sohne geht erst mit static-ifs.</p>
</blockquote>
<p>Ähm...nein!?</p>
</blockquote>
<p>Zeig mal wie du das ohne Dispatch machst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325618</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:28:19 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:31:16 GMT]]></title><description><![CDATA[<p>Na mit ifs?<br />
<a href="http://ideone.com/YI1x5J" rel="nofollow">http://ideone.com/YI1x5J</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325620</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325620</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 23 May 2013 18:31:16 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:35:40 GMT]]></title><description><![CDATA[<p>Das war ja auch meine Idee. Da die Adresse des Zeigers einmalig ist. Aber wie stelle ich das jetzt an? Folgende Funktion:</p>
<pre><code>template &lt;class TKey, class TValue&gt;
void HashMap&lt;TKey, TValue&gt;::Add(const TKey&amp; key, const TValue&amp; value)
{
    ...
    int hashCode = /* hier brauche ich den HashCode*/ &amp; 0x7fffffff;
    ...
}
</code></pre>
<p>Woher bekomme ich nun den HashCode bzw. woher weiß ich, dass &quot;key&quot; ein Zeiger oder Objekt ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325622</guid><dc:creator><![CDATA[Enumerator]]></dc:creator><pubDate>Thu, 23 May 2013 18:35:40 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:36:03 GMT]]></title><description><![CDATA[<p>Aha. <a href="http://ideone.com/xLjXxZ" rel="nofollow">http://ideone.com/xLjXxZ</a>. Schonmal an den Fall vom OP gedacht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325623</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:36:03 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:46:42 GMT]]></title><description><![CDATA[<p>Ja, du wirst so nicht arbeiten können, denn der Code wird nun einmal - sobald das Template instantiiert wird - komplett geschluckt und geprüft.</p>
<p>Wenn du bei Memberfunktionen in Klassentemplates Unterscheidung für mehrere verschiedenen Template-Parameter haben willst, nutze einen Trick. Das Int-To-Type Idiom.</p>
<p>Das ist eine hingekotzte Version, das geht bestimmt schöner:</p>
<pre><code>#include&lt;iostream&gt;

template&lt;typename TParam&gt;
class MyClass
{
    /// Definition für Referenzen
    void MyFunction( TParam const&amp;,
                     std::integral_constant&lt;bool, false&gt;, std::integral_constant&lt;bool, true&gt; );

    /// Definition für Zeiger
    void MyFunction( TParam const&amp;,
                     std::integral_constant&lt;bool, true&gt;, std::integral_constant&lt;bool, false&gt; );

public:

    void MyFunction( TParam const&amp; param )
    {
        MyFunction(param,
                   std::integral_constant&lt;bool, std::is_pointer&lt;TParam&gt;::value&gt;(),
                   std::integral_constant&lt;bool, std::is_reference&lt;TParam&gt;::value&gt;());
    }
};

template &lt;class TParam&gt;
void MyClass&lt;TParam&gt;::MyFunction(const TParam&amp; param,
                                 std::integral_constant&lt;bool, false&gt;, std::integral_constant&lt;bool, true&gt;)
{
    param &lt;&lt; &quot;Lol&quot;;
}

template &lt;class TParam&gt;
void MyClass&lt;TParam&gt;::MyFunction(const TParam&amp; param,
                                 std::integral_constant&lt;bool, true&gt;, std::integral_constant&lt;bool, false&gt;)
{
    (*param) &lt;&lt; &quot;Lol&quot;;
}

int main()
{
    MyClass&lt;std::ostream*&gt;().MyFunction(&amp;std::cout);
    MyClass&lt;std::ostream&amp;&gt;().MyFunction(std::cout);
}
</code></pre>
<p>Edit: Jup, hier wird das schöner gemacht - sieh dir das Beispiel an: <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Int-To-Type" rel="nofollow">http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Int-To-Type</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325624</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 23 May 2013 18:46:42 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:38:21 GMT]]></title><description><![CDATA[<p>deinvater schrieb:</p>
<blockquote>
<p>Wenn du schon einen Pointer hast =&gt; DAS IST DEIN HASH!!!</p>
</blockquote>
<p>Das heißt, für gleiche Pointees gibt es unterschiedliche Hashwerte? Lol!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325625</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 23 May 2013 18:38:21 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:39:14 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/32227">@Enumerator</a>:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
int getHashCode(T* t) { return reinterpret_cast&lt;long&gt;(t); }

template &lt;typename T&gt;
int getHashCode(T&amp; t) { return t.getHashCode(); }

struct S {int getHashCode()const{return 0;}};
int main()
{
  S s;
  getHashCode(s);
  getHashCode(&amp;s);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2325626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325626</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:39:14 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:41:47 GMT]]></title><description><![CDATA[<p>deinvater schrieb:</p>
<blockquote>
<p>Aha. <a href="http://ideone.com/xLjXxZ" rel="nofollow">http://ideone.com/xLjXxZ</a>. Schonmal an den Fall vom OP gedacht?</p>
</blockquote>
<p>Nö.<br />
Nur bis &quot;wie kann ich zwischen Pointer und nicht Pointer unterscheiden gelesen&quot;. Und das geht so.<br />
*duck und weg*</p>
<p>Edit:</p>
<p>Sone schrieb:</p>
<blockquote>
<p>deinvater schrieb:</p>
<blockquote>
<p>Wenn du schon einen Pointer hast =&gt; DAS IST DEIN HASH!!!</p>
</blockquote>
<p>Das heißt, für gleiche Pointees gibt es unterschiedliche Hashwerte? Lol!</p>
</blockquote>
<p>Schaue dir mal die std::hash&lt;T*&gt; Implementierung deines Compilers an. Oh.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325627</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 23 May 2013 18:41:47 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:41:06 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>deinvater schrieb:</p>
<blockquote>
<p>Wenn du schon einen Pointer hast =&gt; DAS IST DEIN HASH!!!</p>
</blockquote>
<p>Das heißt, für gleiche Pointees gibt es unterschiedliche Hashwerte? Lol!</p>
</blockquote>
<p>Es handelt sich um &quot;nicht kopierbare Objekte habe (z.B. GUI-Controls)&quot;. Für nicht kopierbare Objekte ist die Identität an den Speicher gekoppelt. Ohne Ausnahme.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325628</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:41:06 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:43:03 GMT]]></title><description><![CDATA[<p>Upsi, ich habe mich vertan, ich dachte an was anderes, du hast Recht <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>Sone schrieb:</p>
<blockquote>
<p>&quot; 9</p>
<p>Sone schrieb:</p>
<blockquote>
<p>deinvater schrieb:</p>
<blockquote>
<p>Wenn du schon einen Pointer hast =&gt; DAS IST DEIN HASH!!!</p>
</blockquote>
<p>Das heißt, für gleiche Pointees gibt es unterschiedliche Hashwerte? Lol!</p>
</blockquote>
<p>Schaue dir mal die std::hash&lt;T*&gt; Implementierung deines Compilers an. Oh.</p>
</blockquote>
<p>Schon klar. Ich habe das völlig missverstanden, ich dachte es ging um was anderes. Natürlich ist der Hash eines Zeigers sein Wert.</p>
<p>So wie halt für jeden Skalar sein Wert sein Hash ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325629</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325629</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 23 May 2013 18:43:03 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:47:30 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<pre><code>std::integral_constant&lt;bool, true&gt;,
std::integral_constant&lt;bool, false&gt;

std::integral_constant&lt;bool, std::is_pointer&lt;TParam&gt;::value&gt;(),
std::integral_constant&lt;bool, std::is_reference&lt;TParam&gt;::value&gt;());
</code></pre>
</blockquote>
<p>lol?</p>
<p>1. std::true_type/std::false_type<br />
2. typename std::is_pointer&lt;T&gt;::type/typename std::is_reference&lt;T&gt;::type</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325630</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325630</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:47:30 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:49:29 GMT]]></title><description><![CDATA[<p>deinvater schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/32227">@Enumerator</a>:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
int getHashCode(T* t) { return reinterpret_cast&lt;long&gt;(t); }

template &lt;typename T&gt;
int getHashCode(T&amp; t) { return t.getHashCode(); }

struct S {int getHashCode()const{return 0;}};
int main()
{
  S s;
  getHashCode(s);
  getHashCode(&amp;s);
}
</code></pre>
</blockquote>
<p>Ok, das schaut schonmal gut aus. Jetzt weiß ich aber immer noch nicht, ob &quot;key&quot; ein Zeiger oder Objekt ist. Also welche der GetHashCode-Funktionen ich aufrufen muss.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325632</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325632</guid><dc:creator><![CDATA[Enumerator]]></dc:creator><pubDate>Thu, 23 May 2013 18:49:29 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:50:45 GMT]]></title><description><![CDATA[<p>Enumerator schrieb:</p>
<blockquote>
<p>deinvater schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/32227">@Enumerator</a>:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
int getHashCode(T* t) { return reinterpret_cast&lt;long&gt;(t); }

template &lt;typename T&gt;
int getHashCode(T&amp; t) { return t.getHashCode(); }

struct S {int getHashCode()const{return 0;}};
int main()
{
  S s;
  getHashCode(s);
  getHashCode(&amp;s);
}
</code></pre>
</blockquote>
<p>Ok, das schaut schonmal gut aus. Jetzt weiß ich aber immer noch nicht, ob &quot;key&quot; ein Zeiger oder Objekt ist. Also welche der GetHashCode-Funktionen ich aufrufen muss.</p>
</blockquote>
<p>Das überlässt du dem Compiler.</p>
<p>Bei</p>
<pre><code class="language-cpp">getHashCode(&lt;irgendetwas&gt;)
</code></pre>
<p>wird automatisch die richtige Überladung ausgewählt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325635</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:50:45 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:52:22 GMT]]></title><description><![CDATA[<p>Zudem hat es den Vorteil, dass du es leicht erweitern kannst. Es genügt,</p>
<pre><code class="language-cpp">int getHashCode(std::string const&amp; s) { return std::hash&lt;std::string&gt;()(s); }
</code></pre>
<p>hinzuzufügen und schon kann dein Container Strings unterstützen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325636</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325636</guid><dc:creator><![CDATA[deinvater]]></dc:creator><pubDate>Thu, 23 May 2013 18:52:22 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 18:57:52 GMT]]></title><description><![CDATA[<p>deinvater schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<pre><code>std::integral_constant&lt;bool, true&gt;,
std::integral_constant&lt;bool, false&gt;

std::integral_constant&lt;bool, std::is_pointer&lt;TParam&gt;::value&gt;(),
std::integral_constant&lt;bool, std::is_reference&lt;TParam&gt;::value&gt;());
</code></pre>
</blockquote>
<p>lol?</p>
<p>1. std::true_type/std::false_type<br />
2. typename std::is_pointer&lt;T&gt;::type/typename std::is_reference&lt;T&gt;::type</p>
</blockquote>
<p>Ja, so kann man es abkürzen. Kopf-&gt;Tisch</p>
<p>Allerdings versagt die Methode, sobald mehr Unterscheidungen im Spiel sind.</p>
<p>Da würde ich es machen wie das Beispiel auf Wikibooks.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325637</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325637</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 23 May 2013 18:57:52 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 19:00:09 GMT]]></title><link>https://www.c-plusplus.net/forum/post/2325638</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325638</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 23 May 2013 19:00:09 GMT</pubDate></item><item><title><![CDATA[Reply to Parametertyp von Templatefunktion feststellen on Thu, 23 May 2013 19:00:58 GMT]]></title><description><![CDATA[<p>deinvater schrieb:</p>
<blockquote>
<p>Zudem hat es den Vorteil, dass du es leicht erweitern kannst. Es genügt, [...] hinzuzufügen und schon kann dein Container Strings unterstützen.</p>
</blockquote>
<p>Du musst aber aufpassen. Deine Templates sind gierig, sie unterbinden implizite Konvertierungen. <code>getHashCode(&quot;text&quot;)</code> geht zum Beispiel schon mal nicht.</p>
<p>Auch wenn du z.B. für <code>long</code> erweiterst und mit einem <code>int</code> aufrufst, wird die allgemeine Version als Überladung ausgewählt. Das kann eventuell unintuitiv sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325639</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325639</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 23 May 2013 19:00:58 GMT</pubDate></item></channel></rss>