<?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[Hashtable-Template]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte nen Template Hashtable&lt;class type1, class type2&gt; schreiben...<br />
Falls type1 von HashValue erbt, möchte ich die den Rückgabe-Wert dieser<br />
Methode nehmen, ansonsten möchte ich die anhand der Adresse einsortieren.</p>
<p>Also etwa so:</p>
<pre><code class="language-cpp">template&lt;class type1, class type2&gt;
class Hashtable{
public:
	Hashtable();
	virtual ~Hashtable();

	virtual void put(type1, type2){
		if (type1 instanceof HashValue)
			// tue dies
		else 
			// tue das
	}
};
</code></pre>
<p>#endif</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/133044/hashtable-template</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 19:04:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/133044.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 14 Jan 2006 22:10:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hashtable-Template on Sat, 14 Jan 2006 22:10:03 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte nen Template Hashtable&lt;class type1, class type2&gt; schreiben...<br />
Falls type1 von HashValue erbt, möchte ich die den Rückgabe-Wert dieser<br />
Methode nehmen, ansonsten möchte ich die anhand der Adresse einsortieren.</p>
<p>Also etwa so:</p>
<pre><code class="language-cpp">template&lt;class type1, class type2&gt;
class Hashtable{
public:
	Hashtable();
	virtual ~Hashtable();

	virtual void put(type1, type2){
		if (type1 instanceof HashValue)
			// tue dies
		else 
			// tue das
	}
};
</code></pre>
<p>#endif</p>
]]></description><link>https://www.c-plusplus.net/forum/post/966788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/966788</guid><dc:creator><![CDATA[Templator]]></dc:creator><pubDate>Sat, 14 Jan 2006 22:10:03 GMT</pubDate></item><item><title><![CDATA[Reply to Hashtable-Template on Sat, 14 Jan 2006 22:11:12 GMT]]></title><description><![CDATA[<p>Kann ich das irgendwie hinkriegen?</p>
<p>Vielen Dank für eure Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/966790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/966790</guid><dc:creator><![CDATA[Templator]]></dc:creator><pubDate>Sat, 14 Jan 2006 22:11:12 GMT</pubDate></item><item><title><![CDATA[Reply to Hashtable-Template on Sun, 15 Jan 2006 15:23:25 GMT]]></title><description><![CDATA[<p>sicher geht das AFAIK nicht. Du kannst zur kompilierzeit nur herausfinden _ob_ eine klasse erbt, nicht ob das public/protected/private ist. Du könntest auch prüfen ob die Klasse ne memberfunktion get_hash_value o.ä. hat (siehe adl), aber das ist auch unschön, weil _theoretisch_ get_hash_value auch was anderes sein könnte, als du erwartest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/966947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/966947</guid><dc:creator><![CDATA[ness]]></dc:creator><pubDate>Sun, 15 Jan 2006 15:23:25 GMT</pubDate></item><item><title><![CDATA[Reply to Hashtable-Template on Sun, 15 Jan 2006 13:52:11 GMT]]></title><description><![CDATA[<p>iirc gilt diese Compilezeit-Ermittlung der Basisklasse nur für öffentliche Basisklassen (da nur dann die Umwandlung implizit funktioniert), ist also hier genau das richtige.</p>
<pre><code class="language-cpp">// so siehts in &quot;Modernes C++ Design&quot; von Alexandrescu aus
template &lt;class T, class U&gt;
class Conversion
{
    typedef char Small;
    class Big { char dummy[2] };
    static Small Test (U);
    static Big Test (...);
    static T MakeT ();
public:
    enum { exists = sizeof (Test (MakeT ())) == sizeof (Small) };
    enum { sameType = 0 };
};

template &lt;class T&gt;
class Conversion&lt;T,T&gt;
{
public:
    enum { exists = 1, sameType = 1 };
};

#define SUPERSUBCLASS(T, U) \
    (Conversion&lt;const U*, const T*&gt;::exists &amp;&amp; \
    !Conversion&lt;const T*, const void*&gt;::sameType)
</code></pre>
<p>Geht teilweise noch eleganter (z.B. ohne enums), aber ist ansonsten Klasse.<br />
Gibts auch in der <a href="http://sourceforge.net/projects/loki-lib/" rel="nofollow">Loki-Bibliothek</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967047</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Sun, 15 Jan 2006 13:52:11 GMT</pubDate></item><item><title><![CDATA[Reply to Hashtable-Template on Sun, 15 Jan 2006 14:14:22 GMT]]></title><description><![CDATA[<blockquote>
<p>Geht teilweise noch eleganter (z.B. ohne enums)</p>
</blockquote>
<p>Ob eleganter sei mal dahingstellt, aber ohne enums und dafür mit SFINAE geht es z.B. so in der Art:</p>
<pre><code class="language-cpp">// check if T extends U
// Note: Fails at compile-time if U is an inaccessible
// of T.
template &lt;class T, class U&gt;
struct Extends {
typedef char (&amp;YesType)[1];
typedef char (&amp;NoType)[2];

static YesType test(const volatile U*);
static NoType test(const volatile void*);

enum { value = sizeof(YesType) == sizeof(test(static_cast&lt;T*&gt;(0)))};

};
</code></pre>
<p>Solche Sachen sollte man imo aber nicht selbst implementieren sondern stattdessein eine ordentliche Bibliothek verwenden. boost::type_traits bietet sich hier natürlich an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967067</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Sun, 15 Jan 2006 14:14:22 GMT</pubDate></item><item><title><![CDATA[Reply to Hashtable-Template on Sun, 15 Jan 2006 14:18:12 GMT]]></title><description><![CDATA[<p>@Templator</p>
<p>Den Test in der if-Bedingung müsstest du in diesem Fall durch Überladung ersetzen. In etwa so:</p>
<pre><code class="language-cpp">template &lt;int I&gt; struct Int2Type {};

template&lt;class type1, class type2&gt;
class Hashtable{
public:
    Hashtable();
    virtual ~Hashtable();
    // nicht virtuell, nur forwarding
    void put(type1 a, type2 b){
        doPut(a, b, Int2Type&lt;Extends&lt;type1, HashValue&gt;::value&gt;());
    }

    // für den Fall, dass type1 von HashValue erbt...
    virtual void doPut(type1, type2, Int2Type&lt;1&gt;);
    // ...andernfalls
    virtual void doPut(type1, type2, Int2Type&lt;0&gt;);
};
</code></pre>
<p>Eine (bessere) Alternative wäre die Verwendendung von boost::enable_if.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967069</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Sun, 15 Jan 2006 14:18:12 GMT</pubDate></item><item><title><![CDATA[Reply to Hashtable-Template on Sun, 15 Jan 2006 15:32:22 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/110">@HumeSikkins</a>: funktioniert das auch wenn T private von U erbt (sprich gibt es dann no zurück)? Wenn ja, warum?<br />
/edit: ah, das meinst du mit erreichbar</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967194</guid><dc:creator><![CDATA[ness]]></dc:creator><pubDate>Sun, 15 Jan 2006 15:32:22 GMT</pubDate></item><item><title><![CDATA[Reply to Hashtable-Template on Mon, 16 Jan 2006 13:21:40 GMT]]></title><description><![CDATA[<p>Nur die öffentliche Vererbung erlaubt die implizite Umwandlung von Zeigern in Ableitungsrichtung (und damit funktionieren beide Tests). Das schrieb ich aber bereits :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967997</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Mon, 16 Jan 2006 13:21:40 GMT</pubDate></item></channel></rss>