<?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[double als const template parameter]]></title><description><![CDATA[<p>Hallo,<br />
gibt es irgendeine Möglichkeit, folgendes zu realisieren?</p>
<pre><code class="language-cpp">template&lt;double d&gt;
class foo
{
};
int main()
{
    foo&lt;1.0&gt; f;
}
</code></pre>
<p>... Ich verstehe auch nicht, wieso das nicht machbar ist. Was ist der grund hierfür?</p>
<p>Danke im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/308559/double-als-const-template-parameter</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 18:05:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/308559.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Sep 2012 16:59:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 16:59:52 GMT]]></title><description><![CDATA[<p>Hallo,<br />
gibt es irgendeine Möglichkeit, folgendes zu realisieren?</p>
<pre><code class="language-cpp">template&lt;double d&gt;
class foo
{
};
int main()
{
    foo&lt;1.0&gt; f;
}
</code></pre>
<p>... Ich verstehe auch nicht, wieso das nicht machbar ist. Was ist der grund hierfür?</p>
<p>Danke im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255368</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Fri, 28 Sep 2012 16:59:52 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:13:41 GMT]]></title><description><![CDATA[<p>Das was du da machst ist irgend ein Murks. Ich nehme an du möchtest folgendes haben:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
class Foo
{
	//...
};

int main()
{
	Foo&lt;double&gt; f;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2255371</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255371</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:24:49 GMT]]></title><description><![CDATA[<p>Ganz einfach, weil laut Standard:</p>
<pre><code>|1|Fehler: »double« ist kein gültiger Typ für einen Templatekonstanten-Parameter|
</code></pre>
<p>Edit: Das &quot;Warum&quot; bekommt man nach ein paar Sekunden googeln:</p>
<p><a href="http://www.c-plusplus.net/forum/p1214921#1214921" rel="nofollow">http://www.c-plusplus.net/forum/p1214921#1214921</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255372</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:24:49 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:24:34 GMT]]></title><description><![CDATA[<p>Ja, Fließkommazahlen gibt es nicht als non-type template-parameter; der Typ <strong>muss integral</strong> sein.</p>
<p>@icarus: Ich glaube, non-type Template-Parameter und Typparameter kann man schlecht verwechseln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255373</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255373</guid><dc:creator><![CDATA[Sone_]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:24:34 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:26:07 GMT]]></title><description><![CDATA[<p>Ne, ich schau mir gerade zum ersten Mal template metaprogrammierung an. Und da trifft man gleich mal auf folgendes Bsp.:</p>
<pre><code class="language-cpp">template &lt;int N&gt;
struct Factorial {
    enum { value = N * Factorial&lt;N - 1&gt;::value };
};

template &lt;&gt;
struct Factorial&lt;0&gt; {
    enum { value = 1 };
};

int main()
{
    const int x = Factorial&lt;4&gt;::value; // == 24
    const int y = Factorial&lt;0&gt;::value; // == 1
}
</code></pre>
<p>Dann hab ich mich gefragt, ob man als int auch double oder sontwas verwenden kann. Das scheint aber nicht zu gehen. Deshalb die Frage. Geht das nur mit Ganzzahlen, oder kann man es über Umwege auch mit anderen Typen erreichen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255374</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:26:07 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:30:21 GMT]]></title><description><![CDATA[<p>Eine Idee wäre, das ganze in einen Bruch umzuschreiben. Möglich wäre es dann, Zähler und Nenner zu übergeben.</p>
<p>Oder vielleicht das ganze mit Exponentialschreibweise und ganzzahliger Mantisse, die <code>&gt;= 10</code> sein darf. Also bspw.</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn><mo separator="true">,</mo><mn>4</mn><mn>5</mn><mn>6</mn></mrow><annotation encoding="application/x-tex">1,456</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.8388800000000001em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span><span class="mpunct">,</span><span class="mord mathrm">4</span><span class="mord mathrm">5</span><span class="mord mathrm">6</span></span></span></span></p>
<p>wäre</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn><mn>4</mn><mn>5</mn><mn>6</mn><mo>∗</mo><mn>1</mn><msup><mn>0</mn><mrow><mo>−</mo><mn>3</mn></mrow></msup></mrow><annotation encoding="application/x-tex">1456 * 10^{-3}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8141079999999999em;"></span><span class="strut bottom" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span><span class="mord mathrm">4</span><span class="mord mathrm">5</span><span class="mord mathrm">6</span><span class="mbin">∗</span><span class="mord mathrm">1</span><span class="mord"><span class="mord mathrm">0</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord scriptstyle uncramped"><span class="mord">−</span><span class="mord mathrm">3</span></span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span></span></span></span></p>
<p>und du nimmst als Template-Parameter einfach die Mantisse und den Exponent als Ganzzahl.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255376</guid><dc:creator><![CDATA[Sone_]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:30:21 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:34:50 GMT]]></title><description><![CDATA[<p>Das sind aber alles Umwege, die sich imo nicht lohnen, um praktisch einsetzbar zu sein. Zudem gibt es ab C++11 Const Expressions, die für dieses Beispiel eingesetzt werden können.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255378</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255378</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:34:50 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:35:31 GMT]]></title><description><![CDATA[<p>Ok.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/25153">@Incocnito</a>: Die Antwort von CStoll hab ich gesehen. Allerdings dachte ich, ich hätte mal ein Proposal gelesen, das soetwas eingeführt werden sollte (kann es aber gerade nicht mehr finden), und es mitterweile irgendwie möglich wäre. Wenn Fließkommazahlen aber wirklich erst zur Laufzeit erzeugt werden können, wäre es ja praktisch unmöglich. Dann frag ich mich aber, an was ich mich da erinnere. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255379</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:35:31 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:37:47 GMT]]></title><description><![CDATA[<p>Quatsch, Fließkommazahlen können natürlich auch zur Kompilierzeit erzeugt werden. Oder denkst Du, dass eine Rechnung wie</p>
<pre><code class="language-cpp">const double z = 1.0 + 9.0;
</code></pre>
<p>zur Laufzeit ausgeführt wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255380</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:37:47 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:44:02 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p>kann man es über Umwege auch mit anderen Typen erreichen?</p>
</blockquote>
<p>Viele Anwendungsfälle können auch durch Verwendung von constexpr-Funktionen gelöst werden.<br />
Im Übrigen kann eine Gleitkommazahl auch durch eine Integersequenz ausgedrückt werden. Auf die Weise ist auch schon pi per TMP berechnet worden.</p>
<p>n3337 schrieb:</p>
<blockquote>
<p>14.1 Template parameters [temp.param]<br />
[...]<br />
4 A non-type <em>template-parameter</em> shall have one of the following (optionally <em>cv-qualified</em>) types:<br />
— integral or enumeration type,<br />
— pointer to object or pointer to function,<br />
— lvalue reference to object or lvalue reference to function,<br />
— pointer to member,<br />
— std::nullptr_t.</p>
<p>[...]<br />
14.3.2 Template non-type arguments [temp.arg.nontype]<br />
1 A <em>template-argument</em> for a non-type, non-template <em>template-parameter</em> shall be one of:<br />
— for a non-type <em>template-parameter</em> of integral or enumeration type, a converted constant expression(5.19) of the type of the <em>template-parameter</em>; or<br />
— the name of a non-type <em>template-parameter</em>; or<br />
— a constant expression (5.19) that designates the address of an object with static storage duration and external or internal linkage or a function with external or internal linkage, including function templates and function template-ids but excluding non-static class members, expressed (ignoring parentheses) as &amp; id-expression, except that the &amp; may be omitted if the name refers to a function or array and shall be omitted if the corresponding <em>template-parameter</em> is a reference; or<br />
— a constant expression that evaluates to a null pointer value (4.10); or<br />
— a constant expression that evaluates to a null member pointer value (4.11); or<br />
— a pointer to member expressed as described in 5.3.1.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2255381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255381</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:44:02 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 17:56:20 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Im Übrigen kann eine Gleitkommazahl auch durch eine Integersequenz ausgedrückt werden. Auf die Weise ist auch schon pi per TMP berechnet worden.</p>
</blockquote>
<p>Hey camper, danke! Jetzt hab' ich für den Abend was zu tun! <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2255390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255390</guid><dc:creator><![CDATA[Sone_]]></dc:creator><pubDate>Fri, 28 Sep 2012 17:56:20 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 18:01:48 GMT]]></title><description><![CDATA[<p>Den gerade zitierten C++ Standard als Draft gibt es hier:<br />
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/" rel="nofollow">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/</a></p>
<p>Nennt sich N3337.pdf und gehört auf jeden Fall in Dein Literatur-Repertoire...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255391</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Fri, 28 Sep 2012 18:01:48 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Fri, 28 Sep 2012 18:31:18 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Quatsch, Fließkommazahlen können natürlich auch zur Kompilierzeit erzeugt werden. Oder denkst Du, dass eine Rechnung wie</p>
<pre><code class="language-cpp">const double z = 1.0 + 9.0;
</code></pre>
<p>zur Laufzeit ausgeführt wird?</p>
</blockquote>
<p>Ne, hast natürlich Recht. <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="😉"
    /></p>
<p>Furble Wurble schrieb:</p>
<blockquote>
<p>Den gerade zitierten C++ Standard als Draft gibt es hier:<br />
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/" rel="nofollow">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/</a></p>
<p>Nennt sich N3337.pdf und gehört auf jeden Fall in Dein Literatur-Repertoire...</p>
</blockquote>
<p>Stimmt, den aktuellen Draft sollte ich mir mal holen.</p>
<p>Danke euch allen. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2255395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255395</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Fri, 28 Sep 2012 18:31:18 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Sat, 29 Sep 2012 02:20:39 GMT]]></title><description><![CDATA[<p>War nicht mal im Gespräch dass sie float/double als non-type Template Parameter erlauben wollen -- eben weil es keinen wirklich guten Grund gibt warum sie nicht erlaubt sind?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255453</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 29 Sep 2012 02:20:39 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Sat, 29 Sep 2012 08:58:59 GMT]]></title><description><![CDATA[<p>Könnte es nicht Probleme wegen der Ungenauigkeit geben?<br />
D.h. wären</p>
<pre><code class="language-cpp">foo&lt;1.0&gt; f;
</code></pre>
<p>und</p>
<pre><code class="language-cpp">foo&lt;3.0*(1.0/3.0)&gt; f;
</code></pre>
<p>die gleiche Instantiierung?<br />
Und es müßte geklärt werden, ob +0.0, -0.0 sowie die verschiedenen NAN-Represesentationen als gleich angesehen werden würden (s. den defacto-Standard <a href="http://de.wikipedia.org/wiki/Ieee754" rel="nofollow">http://de.wikipedia.org/wiki/Ieee754</a>).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255482</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sat, 29 Sep 2012 08:58:59 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Sat, 29 Sep 2012 09:22:24 GMT]]></title><description><![CDATA[<p>Furble Wurble schrieb:</p>
<blockquote>
<p>Den gerade zitierten C++ Standard als Draft gibt es hier:<br />
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/" rel="nofollow">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/</a></p>
<p>Nennt sich N3337.pdf und gehört auf jeden Fall in Dein Literatur-Repertoire...</p>
</blockquote>
<p>Nennt sich wohl eher N3376.pdf <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255485</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 29 Sep 2012 09:22:24 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Sat, 29 Sep 2012 09:30:38 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Furble Wurble schrieb:</p>
<blockquote>
<p>Den gerade zitierten C++ Standard als Draft gibt es hier:<br />
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/" rel="nofollow">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/</a></p>
<p>Nennt sich N3337.pdf und gehört auf jeden Fall in Dein Literatur-Repertoire...</p>
</blockquote>
<p>Nennt sich wohl eher N3376.pdf <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
</blockquote>
<p><strong>¡Ay, caramba!</strong> <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2255489</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255489</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Sat, 29 Sep 2012 09:30:38 GMT</pubDate></item><item><title><![CDATA[Reply to double als const template parameter on Sat, 29 Sep 2012 09:32:38 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Furble Wurble schrieb:</p>
<blockquote>
<p>Den gerade zitierten C++ Standard als Draft gibt es hier:<br />
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/" rel="nofollow">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/</a></p>
<p>Nennt sich N3337.pdf und gehört auf jeden Fall in Dein Literatur-Repertoire...</p>
</blockquote>
<p>Nennt sich wohl eher N3376.pdf <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
</blockquote>
<p>n3337 enthält im Gegensatz zu n3376 nur redaktionelle Änderungen gegenüber dem Standard.<br />
n3376 enthält demgegenüber bereits Änderungen, die ggf. mal in der nächsten Revision des Standards auftauchen werden, ist aber folglich ungeeignet, den gegenwärtig verbindlichen Stand abzubilden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2255491</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2255491</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 29 Sep 2012 09:32:38 GMT</pubDate></item></channel></rss>