<?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[template spezialisierung]]></title><description><![CDATA[<p>hola</p>
<p>ich haeng da gerade bei einem template problem.<br />
ich habe einen base-klasse:</p>
<pre><code>template&lt;data_types DATA_TYPE, int WIDTH = 0&gt;
class base_type;
</code></pre>
<p>nun spezialisiere ich sie fuer verschiedene datentypen die ich als enum klassifiziere:</p>
<pre><code>enum class data_types
{
   unknown = 0,
   integer = 1,
   boolean = 2,
   string = 3,
   date = 4,
   time = 5,
   real = 6
}; /* enum class data_types */

template&lt;&gt;
class base_type&lt;data_types::string&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      std::string m_string;
}; /* class base_type&lt;data_types::string&gt; */

template&lt;&gt;
class base_type&lt;data_types::integer&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      std::string m_string;
}; /* class base_type&lt;data_types::string&gt; */
</code></pre>
<p>der 2te template parameter WIDTH ist fuer die strings und fuer die anderen unbeachtet.<br />
nun moechte ich aber weiter spezialisieren. und zwar folgend:<br />
wenn ich data_types::string als template uebergebe und einen int-wert &lt;= 24 fuer WIDTH, moechte ich keinen std::string verwenden sondern ein char[WIDTH].</p>
<pre><code>base_type&lt;data_type::string, 24&gt; string_type1;
base_type&lt;data_type::string, 300&gt; string_type2;
</code></pre>
<p>in pseudoschreibweise moechte cih also folgendes haben:</p>
<pre><code>template&lt;&gt;
class base_type&lt;data_types::string, WIDTH&lt;=24&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      char m_string[WIDTH];
}; /* class base_type&lt;data_types::string&gt; */

template&lt;&gt;
class base_type&lt;data_types::string, WIDTH &gt; 24&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      std::string m_string;
}; /* class base_type&lt;data_types::string&gt; */
</code></pre>
<p>wie stelle ich das an ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/338268/template-spezialisierung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 18:27:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/338268.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Jun 2016 20:13:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to template spezialisierung on Sat, 04 Jun 2016 20:13:27 GMT]]></title><description><![CDATA[<p>hola</p>
<p>ich haeng da gerade bei einem template problem.<br />
ich habe einen base-klasse:</p>
<pre><code>template&lt;data_types DATA_TYPE, int WIDTH = 0&gt;
class base_type;
</code></pre>
<p>nun spezialisiere ich sie fuer verschiedene datentypen die ich als enum klassifiziere:</p>
<pre><code>enum class data_types
{
   unknown = 0,
   integer = 1,
   boolean = 2,
   string = 3,
   date = 4,
   time = 5,
   real = 6
}; /* enum class data_types */

template&lt;&gt;
class base_type&lt;data_types::string&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      std::string m_string;
}; /* class base_type&lt;data_types::string&gt; */

template&lt;&gt;
class base_type&lt;data_types::integer&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      std::string m_string;
}; /* class base_type&lt;data_types::string&gt; */
</code></pre>
<p>der 2te template parameter WIDTH ist fuer die strings und fuer die anderen unbeachtet.<br />
nun moechte ich aber weiter spezialisieren. und zwar folgend:<br />
wenn ich data_types::string als template uebergebe und einen int-wert &lt;= 24 fuer WIDTH, moechte ich keinen std::string verwenden sondern ein char[WIDTH].</p>
<pre><code>base_type&lt;data_type::string, 24&gt; string_type1;
base_type&lt;data_type::string, 300&gt; string_type2;
</code></pre>
<p>in pseudoschreibweise moechte cih also folgendes haben:</p>
<pre><code>template&lt;&gt;
class base_type&lt;data_types::string, WIDTH&lt;=24&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      char m_string[WIDTH];
}; /* class base_type&lt;data_types::string&gt; */

template&lt;&gt;
class base_type&lt;data_types::string, WIDTH &gt; 24&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      std::string m_string;
}; /* class base_type&lt;data_types::string&gt; */
</code></pre>
<p>wie stelle ich das an ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497897</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sat, 04 Jun 2016 20:13:27 GMT</pubDate></item><item><title><![CDATA[Reply to template spezialisierung on Sat, 04 Jun 2016 23:03:34 GMT]]></title><description><![CDATA[<blockquote>
<p>der 2te template parameter WIDTH ist fuer die strings und fuer die anderen unbeachtet.</p>
</blockquote>
<p>Komisches Design.</p>
<blockquote>
<p>wie stelle ich das an ?</p>
</blockquote>
<p>Es gibt mehrere Optionen. Mein Vorschlag ist SFINAE:</p>
<pre><code>template &lt;data_types DATA_TYPE, int WIDTH = 0, typename = void&gt;
class base_type;

// [...]

template &lt;int WIDTH&gt;
class base_type&lt;data_types::string, WIDTH, std::enable_if_t&lt;WIDTH&lt;=24&gt;&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      char m_string[WIDTH];
}; /* class base_type&lt;data_types::string&gt; */

template &lt;int WIDTH&gt;
class base_type&lt;data_types::string, WIDTH, std::enable_if_t&lt;(WIDTH &gt; 24)&gt;&gt; : public base_type_interface
{
   public:
      virtual auto set(const char *str) noexcept -&gt; int;
      virtual auto get(void) const noexcept -&gt; const char*;
      virtual auto underlying_data_type(void) const noexcept -&gt; data_types;

   private:
      std::string m_string;
}; /* class base_type&lt;data_types::string&gt; */
</code></pre>
<p>(ungetestet)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497908</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 04 Jun 2016 23:03:34 GMT</pubDate></item><item><title><![CDATA[Reply to template spezialisierung on Sun, 05 Jun 2016 04:06:09 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<pre><code>template &lt;data_types DATA_TYPE, int WIDTH = 0, typename = void&gt;
</code></pre>
</blockquote>
<p><code>typename = void</code> ist mir bewust noch nicht untergekommen. was genau bewirkt der template-parameter ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497910</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497910</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sun, 05 Jun 2016 04:06:09 GMT</pubDate></item><item><title><![CDATA[Reply to template spezialisierung on Sun, 05 Jun 2016 07:51:35 GMT]]></title><description><![CDATA[<p>Das ist nur Platzhalter für die Vorwärst-Deklarierung. Für alle Spezialisierungen, bei denen <code>data_types</code> nicht <code>string</code> ist, möchtest du ja i.A. nicht die gleiche SFINAE-Option haben, sondern entweder eine andere oder garkeine (also einfach <code>void</code> als Typ).</p>
<p>Edit: Außerdem gibst du damit den Typen vor, der durch das <code>enable_if</code> dort eingesetzt werden soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497912</guid><dc:creator><![CDATA[Jodocus]]></dc:creator><pubDate>Sun, 05 Jun 2016 07:51:35 GMT</pubDate></item></channel></rss>