<?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[Metaprogrammierung Limits]]></title><description><![CDATA[<p>Hi, lese gerade einige Sachen über Metaprogrammierung und finde immer die Warnung, dass mans mit Rekursionen nicht übertreiben soll und der Compiler relativ schnell an seine Grenzen stösst.<br />
Könnte mir jemand erklären, wovon diese Begrenzung/maximale Tiefe abhängt?<br />
Ist diese Grenze eventuell anpassbar? (Habe in VS08 bislang noch nix gefunden)</p>
<p>Eine &quot;maximale Tiefe&quot; ist wohl auf nur einen(1) rekursiven Lauf bezogen, bei mir macht der Compiler bei Tiefe 500 schlapp.</p>
<p>Ich teste das ganze hiermit:</p>
<pre><code>// -----------------IF THEN ELSE-------------------------
template&lt; bool condition, typename Then, typename Else &gt;
struct IF
{
	typedef Then RET;
};

template&lt; typename Then, typename Else &gt;
struct IF&lt;false, Then,Else &gt;
{
	typedef Else RET;
};
// ------------------------------------------------------

template&lt; int N &gt;
struct Value
{
	enum { result = N };
};

template&lt; int N, int U = IF&lt; !(N%2), Value&lt;0&gt;, Value&lt;N&gt; &gt;::RET::result  &gt;
struct OnlyPositive
{

	typedef typename IF&lt; !(N%2), OnlyPositive&lt;N-1,N-1&gt;, OnlyPositive&lt;N-1,0&gt; &gt;::RET SubRET;
	enum { result = N - U + SubRET::result };
};

template&lt;&gt;
struct OnlyPositive&lt;0,0&gt;
{
	enum { result = 0 };
};

int main()
{
  // std::cout &lt;&lt; OnlyPositive&lt; 499 &gt;::result; // Compiler fehler
     std::cout &lt;&lt; OnlyPositive&lt; 495 &gt;::result; // OK
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/244695/metaprogrammierung-limits</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 04:49:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244695.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Jul 2009 09:10:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Metaprogrammierung Limits on Sat, 04 Jul 2009 09:10:56 GMT]]></title><description><![CDATA[<p>Hi, lese gerade einige Sachen über Metaprogrammierung und finde immer die Warnung, dass mans mit Rekursionen nicht übertreiben soll und der Compiler relativ schnell an seine Grenzen stösst.<br />
Könnte mir jemand erklären, wovon diese Begrenzung/maximale Tiefe abhängt?<br />
Ist diese Grenze eventuell anpassbar? (Habe in VS08 bislang noch nix gefunden)</p>
<p>Eine &quot;maximale Tiefe&quot; ist wohl auf nur einen(1) rekursiven Lauf bezogen, bei mir macht der Compiler bei Tiefe 500 schlapp.</p>
<p>Ich teste das ganze hiermit:</p>
<pre><code>// -----------------IF THEN ELSE-------------------------
template&lt; bool condition, typename Then, typename Else &gt;
struct IF
{
	typedef Then RET;
};

template&lt; typename Then, typename Else &gt;
struct IF&lt;false, Then,Else &gt;
{
	typedef Else RET;
};
// ------------------------------------------------------

template&lt; int N &gt;
struct Value
{
	enum { result = N };
};

template&lt; int N, int U = IF&lt; !(N%2), Value&lt;0&gt;, Value&lt;N&gt; &gt;::RET::result  &gt;
struct OnlyPositive
{

	typedef typename IF&lt; !(N%2), OnlyPositive&lt;N-1,N-1&gt;, OnlyPositive&lt;N-1,0&gt; &gt;::RET SubRET;
	enum { result = N - U + SubRET::result };
};

template&lt;&gt;
struct OnlyPositive&lt;0,0&gt;
{
	enum { result = 0 };
};

int main()
{
  // std::cout &lt;&lt; OnlyPositive&lt; 499 &gt;::result; // Compiler fehler
     std::cout &lt;&lt; OnlyPositive&lt; 495 &gt;::result; // OK
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1736970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1736970</guid><dc:creator><![CDATA[Chris19]]></dc:creator><pubDate>Sat, 04 Jul 2009 09:10:56 GMT</pubDate></item><item><title><![CDATA[Reply to Metaprogrammierung Limits on Sat, 04 Jul 2009 09:12:54 GMT]]></title><description><![CDATA[<p>Abhängig ist die tiefe lediglich von der Grösse des Stacks. Sprich es gibt einen Stakcoverflow, wenn du es übertreibst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1736971</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1736971</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sat, 04 Jul 2009 09:12:54 GMT</pubDate></item><item><title><![CDATA[Reply to Metaprogrammierung Limits on Sat, 04 Jul 2009 10:26:18 GMT]]></title><description><![CDATA[<p>Naja, die Tiefe ist auch abhängig von der Kompilierzeit <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> evilissimo hat hier mal ein Beispiel gebracht, das man auf einem sehr starken Rechner nicht in einigen Tagen kompilieren konnte.</p>
<p>[Edit] Hier ists: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-136704-and-postdays-is-0-and-postorder-is-asc-and-start-is-0.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-136704-and-postdays-is-0-and-postorder-is-asc-and-start-is-0.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1736988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1736988</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Sat, 04 Jul 2009 10:26:18 GMT</pubDate></item></channel></rss>