<?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[Partial Specialization Question]]></title><description><![CDATA[<p>Ich möchte etwas in der folgenden Art realisieren:</p>
<pre><code>template &lt;unsigned A, unsigned B&gt;
struct Blatt
{
    struct Code { enum : unsigned { value = A }; };
    struct Count { enum : unsigned { value = B }; };
};

template &lt;typename LhsT, RhsT, unsigned Count&gt;
struct Knoten
{
    struct Left { using type = LhsT }; // left path in binary tree
    struct Right { using type = RhsT }; // right path in binary tree
    struct Count { enum : unsigned { value = Count; } };
};

template &lt;typename Tree&gt;
class CodeGenerator
{
// fehler?
};

template&lt;&gt;
class CodeGenerator &lt;Blatt&lt;EGAL, EGAL&gt;&gt;
{
// metaprogramm A
};

template&lt;&gt;
class CodeGenerator &lt;Knoten&lt;EGAL, EGAL, EGAL&gt;&gt;
{
// metaprogramm B
};
</code></pre>
<p>CodeGenerator läuft über einen binären Baum, der aus Knoten und Blättern besteht. Jetzt möchte ich Blätter anders als Knoten behandeln und die Blätter als Abbruchbedingung der Rekursion verwenden.</p>
<p>Ich hoffe mein Konstrukt ist nicht fundamentalfalsch angelegt -.-</p>
<p>Allerdings ist mein Template Spezialisierungs Skill nicht hoch genug um den obigen Zauber zu casten :&lt;</p>
<p>[Randinfo: Das hier ist ein Projekt um Boost::MPL zu lernen. Es wird eine Huffmancodierung aus einem Beispieltext erstellt. Der Baum wird korrekt aufgebaut und &quot;CodeGenerator&quot; soll nun wieder von Wurzel bis Blatt runterlaufen und dabei eine CodeSequence erstellen.]</p>
<p>EDIT: obiger code ist hier im Forum entstanden, da der tatsächliche Code deutlich komplizierter ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328857/partial-specialization-question</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 07:39:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328857.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 Oct 2014 18:55:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Partial Specialization Question on Wed, 29 Oct 2014 19:02:16 GMT]]></title><description><![CDATA[<p>Ich möchte etwas in der folgenden Art realisieren:</p>
<pre><code>template &lt;unsigned A, unsigned B&gt;
struct Blatt
{
    struct Code { enum : unsigned { value = A }; };
    struct Count { enum : unsigned { value = B }; };
};

template &lt;typename LhsT, RhsT, unsigned Count&gt;
struct Knoten
{
    struct Left { using type = LhsT }; // left path in binary tree
    struct Right { using type = RhsT }; // right path in binary tree
    struct Count { enum : unsigned { value = Count; } };
};

template &lt;typename Tree&gt;
class CodeGenerator
{
// fehler?
};

template&lt;&gt;
class CodeGenerator &lt;Blatt&lt;EGAL, EGAL&gt;&gt;
{
// metaprogramm A
};

template&lt;&gt;
class CodeGenerator &lt;Knoten&lt;EGAL, EGAL, EGAL&gt;&gt;
{
// metaprogramm B
};
</code></pre>
<p>CodeGenerator läuft über einen binären Baum, der aus Knoten und Blättern besteht. Jetzt möchte ich Blätter anders als Knoten behandeln und die Blätter als Abbruchbedingung der Rekursion verwenden.</p>
<p>Ich hoffe mein Konstrukt ist nicht fundamentalfalsch angelegt -.-</p>
<p>Allerdings ist mein Template Spezialisierungs Skill nicht hoch genug um den obigen Zauber zu casten :&lt;</p>
<p>[Randinfo: Das hier ist ein Projekt um Boost::MPL zu lernen. Es wird eine Huffmancodierung aus einem Beispieltext erstellt. Der Baum wird korrekt aufgebaut und &quot;CodeGenerator&quot; soll nun wieder von Wurzel bis Blatt runterlaufen und dabei eine CodeSequence erstellen.]</p>
<p>EDIT: obiger code ist hier im Forum entstanden, da der tatsächliche Code deutlich komplizierter ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424750</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Wed, 29 Oct 2014 19:02:16 GMT</pubDate></item><item><title><![CDATA[Reply to Partial Specialization Question on Wed, 29 Oct 2014 19:14:11 GMT]]></title><description><![CDATA[<p>Etwa so?</p>
<pre><code>template&lt;unsigned A, unsigned B&gt;
class CodeGenerator &lt;Blatt&lt;A,B&gt;&gt;
{
    // [...]
};

template &lt;typename LhsT, typename RhsT, unsigned Count&gt;
class CodeGenerator &lt;Knoten&lt;LhsT, RhsT, Count&gt;&gt;
{
    // [...]
};
</code></pre>
<p>Ich würde übrigens mehrere Knoten/Blätter in einem Knoten wenn möglich durch variadische Templates behandeln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424755</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 29 Oct 2014 19:14:11 GMT</pubDate></item><item><title><![CDATA[Reply to Partial Specialization Question on Wed, 29 Oct 2014 19:22:46 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Etwa so?</p>
<pre><code>template&lt;unsigned A, unsigned B&gt;
class CodeGenerator &lt;Blatt&lt;A,B&gt;&gt;
{
    // [...]
};
 
template &lt;typename LhsT, typename RhsT, unsigned Count&gt;
class CodeGenerator &lt;Knoten&lt;LhsT, RhsT, Count&gt;&gt;
{
    // [...]
};
</code></pre>
</blockquote>
<p>Ja theoretisch schon, aber Lhs, Rhs und Count müssten aus<br />
Tree (siehe mein Beispiel Code) hervorgehen. (EDIT: und A, <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="B)"
      alt="😎"
    /> Das ginge nur wenn die Parameter automatisch deduziert werden könnten.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Ich würde übrigens mehrere Knoten/Blätter in einem Knoten wenn möglich durch variadische Templates behandeln.</p>
</blockquote>
<p>Was meinst du damit? &quot;mehrere Knoten/Blätter in einem Knoten&quot; bei einem binären Baum? kann doch gar nicht. Habe dich vermutlich falsch verstanden.</p>
<p>EDIT:</p>
<p>Beispiel:</p>
<pre><code>Tree=
Knoten&lt;
    Knoten&lt;
        Blatt&lt;?, ?&gt;, 
        Knoten&lt;
            Blatt&lt;?, ?&gt;, 
            Blatt&lt;?, ?&gt;
        &gt;
    &gt;
&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2424759</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424759</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Wed, 29 Oct 2014 19:22:46 GMT</pubDate></item><item><title><![CDATA[Reply to Partial Specialization Question on Wed, 29 Oct 2014 19:22:50 GMT]]></title><description><![CDATA[<blockquote>
<p>Das ginge nur wenn die Parameter automatisch deduziert werden könnten.</p>
</blockquote>
<p>Und warum können die Argumente nicht deduziert werden? Kannst du mal ein klitzekleines Testprogramm liefern?</p>
<blockquote>
<p>&quot;mehrere Knoten/Blätter in einem Knoten&quot; bei einem binären Baum? kann doch gar nicht. Habe dich vermutlich falsch verstanden.</p>
</blockquote>
<p>Das binär hab' ich überlesen, damit bin ich derjenige der nicht verstanden hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424761</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 29 Oct 2014 19:22:50 GMT</pubDate></item><item><title><![CDATA[Reply to Partial Specialization Question on Wed, 29 Oct 2014 19:33:48 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Kannst du mal ein klitzekleines Testprogramm liefern?</p>
</blockquote>
<p>Ja ein Augenblick</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424764</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Wed, 29 Oct 2014 19:33:48 GMT</pubDate></item><item><title><![CDATA[Reply to Partial Specialization Question on Wed, 29 Oct 2014 19:46:19 GMT]]></title><description><![CDATA[<p>Es kann sein, dass der Inhalt von CodeGenerator noch nicht Sinn ergibt.<br />
Ich war da mittendrin im Gedankenprozess.</p>
<pre><code>#include &lt;boost/mpl/vector.hpp&gt;
#include &lt;boost/mpl/push_back.hpp&gt;

namespace mpl = boost::mpl;

template &lt;typename LhsT, // another node or a leaf
          typename RhsT, // another node or a leaf
          unsigned CountV&gt; // the occurence count or probability (whichever you like to use)
struct BinaryTreeNode
{
    struct Left { using type = LhsT; }; // 1 side
    struct Right { using type = RhsT; }; // 0 side

    // Count is an internal convention for the probabilty
    struct Count { static constexpr unsigned value = CountV; };
};

template &lt;char SymbolV, unsigned CountV&gt;
struct Codeword
{
    struct Symbol { static constexpr unsigned value = SymbolV; };
    struct Count { static constexpr unsigned value = CountV; };
};

// for leaves
template &lt;typename TreeT,
          typename CodeAccumulatorT&gt;
struct CodeGenerator
{
	using type = TreeT; // which is of type &quot;Codeword&quot;

    struct Code { using type = CodeAccumulatorT; };
};

// for nodes
template &lt;typename TreeT,
          typename CodeAccumulatorT&gt;
struct CodeGenerator &lt;?&gt; // &lt;- this
{
	struct Left // subtree
	{
		using type = typename CodeGenerator &lt;typename TreeT::Left::type,
											 typename mpl::push_back &lt;CodeAccumulatorT, mpl::bool_&lt;1&gt;::type&gt;::type
											&gt;::type;
	};
	struct Right // subtree
	{
		using type = typename CodeGenerator &lt;typename TreeT::Right::type,
											 typename mpl::push_back &lt;CodeAccumulatorT, mpl::bool_&lt;0&gt;::type&gt;::type
											&gt;::type;
	};

	using type = TreeT;
};

// hier ein generierter Baum:
// kommt aus &quot;NodeFactory&quot; (hier nicht mit drin um es kurz zu halten)
using Tree =
    boost::mpl::v_item&lt;BinaryTreeNode&lt;BinaryTreeNode&lt;BinaryTreeNode&lt;Codeword&lt;(char)117, 5u&gt;, BinaryTreeNode&lt;BinaryTreeNode&lt;Codeword&lt;(char)98,
	1u&gt;, Codeword&lt;(char)112, 1u&gt;, 2u&gt;, Codeword&lt;(char)106, 3u&gt;, 5u&gt;, 10u&gt;, BinaryTreeNode&lt;Codeword&lt;(char)108, 6u&gt;, Codeword&lt;(char)115, 6u&gt;,
	12u&gt;, 22u&gt;, BinaryTreeNode&lt;BinaryTreeNode&lt;BinaryTreeNode&lt;Codeword&lt;(char)111, 3u&gt;, Codeword&lt;(char)100, 3u&gt;, 6u&gt;, Codeword&lt;(char)101, 8u&gt;,
	14u&gt;, BinaryTreeNode&lt;BinaryTreeNode&lt;Codeword&lt;(char)97, 4u&gt;, Codeword&lt;(char)105, 4u&gt;, 8u&gt;, BinaryTreeNode&lt;BinaryTreeNode&lt;Codeword&lt;(char)39,
	2u&gt;, Codeword&lt;(char)109, 2u&gt;, 4u&gt;, Codeword&lt;(char)114, 5u&gt;, 9u&gt;, 17u&gt;, 31u&gt;, 53u&gt;, boost::mpl::vector0&lt;mpl_::na&gt;, 0&gt;::type;

using result = CodeGenerator &lt;Tree, mpl::vector &lt;&gt;&gt;::type;

int main()
{
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2424768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424768</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Wed, 29 Oct 2014 19:46:19 GMT</pubDate></item><item><title><![CDATA[Reply to Partial Specialization Question on Wed, 29 Oct 2014 19:58:17 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">// for nodes
template &lt;typename LhsT, typename RhsT, unsigned CountV,
          typename CodeAccumulatorT&gt;
struct CodeGenerator &lt;BinaryTreeNode&lt;LhsT,RhsT,CountV&gt;,CodeAccumulatorT&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2424769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424769</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 29 Oct 2014 19:58:17 GMT</pubDate></item><item><title><![CDATA[Reply to Partial Specialization Question on Thu, 30 Oct 2014 00:03:27 GMT]]></title><description><![CDATA[<p>... ok (getestet, code abgeändert und läuft)</p>
<p>Ich glaube ich verstehe Spezialisierung jetzt besser als vorher.</p>
<p>EDIT: es läuft jetzt auch komplett. Ich danke für die Hilfe.<br />
Mit Template Meta Programmierung macht das Programmieren wieder Spaß!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424777</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Thu, 30 Oct 2014 00:03:27 GMT</pubDate></item></channel></rss>