<?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 parameter is not of integral or enumeration type]]></title><description><![CDATA[<p>Moin,<br />
ich versuche mich gerade in templates einzuarbeiten und ich würde für dieses Beispiel gerne die Syntax in Zeile 12 verwenden. Leider kriege ich nicht raus, wie ich Zeile 3 schreiben muss, damit es klappt:</p>
<pre><code>error: template parameter ‘seq’ of type ‘const string&amp; {aka const std::basic_string&lt;char&gt;&amp;}’ is not allowed in an integral constant expression because it is not of integral or enumeration type
</code></pre>
<p>Der Fehler-Meldung entnehme ich, dass man sowas nicht mit strings (oder sonstige not-integrals) machen kann oder übersehe ich was?</p>
<pre><code>#include &lt;string&gt;

template&lt;typename std::string seq, int n&gt;
struct isPalindrome
{
    enum { value = n &lt; 2 ? true : seq[0] == seq[n-1] &amp;&amp; isPalindrome&lt;seq.substr(1, n-2),n-2&gt;::value };
};

int main()
{
    std::string seq = &quot;reliefpfeiler&quot;;
    std::cout &lt;&lt; isPalindrome&lt;seq, seq.length()&gt;::value &lt;&lt; '\n';
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/330598/template-parameter-is-not-of-integral-or-enumeration-type</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Jul 2026 02:32:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/330598.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 18 Jan 2015 03:28:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 03:28:04 GMT]]></title><description><![CDATA[<p>Moin,<br />
ich versuche mich gerade in templates einzuarbeiten und ich würde für dieses Beispiel gerne die Syntax in Zeile 12 verwenden. Leider kriege ich nicht raus, wie ich Zeile 3 schreiben muss, damit es klappt:</p>
<pre><code>error: template parameter ‘seq’ of type ‘const string&amp; {aka const std::basic_string&lt;char&gt;&amp;}’ is not allowed in an integral constant expression because it is not of integral or enumeration type
</code></pre>
<p>Der Fehler-Meldung entnehme ich, dass man sowas nicht mit strings (oder sonstige not-integrals) machen kann oder übersehe ich was?</p>
<pre><code>#include &lt;string&gt;

template&lt;typename std::string seq, int n&gt;
struct isPalindrome
{
    enum { value = n &lt; 2 ? true : seq[0] == seq[n-1] &amp;&amp; isPalindrome&lt;seq.substr(1, n-2),n-2&gt;::value };
};

int main()
{
    std::string seq = &quot;reliefpfeiler&quot;;
    std::cout &lt;&lt; isPalindrome&lt;seq, seq.length()&gt;::value &lt;&lt; '\n';
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2438166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438166</guid><dc:creator><![CDATA[itsame]]></dc:creator><pubDate>Sun, 18 Jan 2015 03:28:04 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 07:56:47 GMT]]></title><description><![CDATA[<p>Was soll denn der Sinn der Sache sein? Wie man Palindrome findet oder wie man Palindorme mittels Template-Metaprogrammierung finden könnte? Letzteres wird recht eklig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438171</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 18 Jan 2015 07:56:47 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 11:51:39 GMT]]></title><description><![CDATA[<blockquote>
<p>Letzteres wird recht eklig.</p>
</blockquote>
<p>Kommt auf den Sprachstandard an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438196</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 18 Jan 2015 11:51:39 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 12:19:37 GMT]]></title><description><![CDATA[<p>Moin Moin,</p>
<p>itsame schrieb:</p>
<blockquote>
<p>Der Fehler-Meldung entnehme ich, dass man sowas nicht mit strings (oder sonstige not-integrals) machen kann oder übersehe ich was?</p>
</blockquote>
<p>richtig, template Parameter können Typen, Templates und einige Konstanten sein. Ein Zeiger auf std::string oder ein String literal wäre möglich, würde Dir aber in Deinem Fall auch nicht weiter helfen, weil Du den Text zur compile Zeit nicht ausgewertet bekommst.</p>
<p>Du müsstest den String als einzelne Zeichen in einen Typen wrappen und dann als Typliste (z.b. boost::mpl::vector) packen. Dann könntest Du zur compile Zeit feststellen, ob der Text eine Palindrom ist.</p>
<p>mfg Torsten</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438202</guid><dc:creator><![CDATA[Torsten Robitzki]]></dc:creator><pubDate>Sun, 18 Jan 2015 12:19:37 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 12:34:14 GMT]]></title><description><![CDATA[<p>Torsten Robitzki schrieb:</p>
<blockquote>
<p>Du müsstest den String als einzelne Zeichen in einen Typen wrappen und dann als Typliste (z.b. boost::mpl::vector) packen. Dann könntest Du zur compile Zeit feststellen, ob der Text eine Palindrom ist.</p>
</blockquote>
<p>Das ist die C++98-Lösung. In C++11 würde man variadic templates und einen const char* als Parameter benützen und in C++14 ist es möglich, eine constexpr_string-Klasse als Template-Argument zu übergeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438207</guid><dc:creator><![CDATA[sprachstandard]]></dc:creator><pubDate>Sun, 18 Jan 2015 12:34:14 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 15:04:20 GMT]]></title><description><![CDATA[<p>sprachstandard schrieb:</p>
<blockquote>
<p>in C++14 ist es möglich, eine constexpr_string-Klasse als Template-Argument zu übergeben.</p>
</blockquote>
<p>Wenn du Objekte meinst: Falsch.</p>
<p>N4140 (C++14 IS/FD) [temp.param]/4 schrieb:</p>
<blockquote>
<p>A non-type template-parameter shall have one of the following (optionally cv-qualified) types:</p>
<ul>
<li>integral or enumeration type,</li>
<li>pointer to object or pointer to function,</li>
<li>lvalue reference to object or lvalue reference to function,</li>
<li>pointer to member,</li>
<li><code>std::nullptr_t</code> .</li>
</ul>
</blockquote>
<p>Wenn du den Typ meinst, macht dein Beitrag keinen Sinn. U.a. weil <code>constexpr</code> nicht Teil von Typen ist.</p>
<blockquote>
<p>In C++11 würde man variadic templates und einen const char* als Parameter benützen</p>
</blockquote>
<p>Nö, letzteres wäre die C++03 Lösung. (Und wie man beides kombinieren soll wäre mir schleierhaft - Indexlisten?) In C++11 geht's mit rekursiven <code>constexpr</code> Funktionen. Und in C++14 mit Schleifen in den <code>constexpr</code> Funktionen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438228</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 18 Jan 2015 15:04:20 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 18:52:47 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>In C++11 würde man variadic templates und einen const char* als Parameter benützen</p>
</blockquote>
<p>Nö, letzteres wäre die C++03 Lösung.</p>
</blockquote>
<p>Variadic Templates in C++03? Haste da nicht was verwechselt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438278</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 18 Jan 2015 18:52:47 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 20:04:01 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>In C++11 würde man variadic templates <em><em>und einen const char</em> als Parameter benützen</em>*</p>
</blockquote>
<p>Nö, <strong>letzteres</strong> wäre die C++03 Lösung.</p>
</blockquote>
<p><strong>Variadic Templates</strong> in C++03? Haste da nicht was verwechselt?</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438302</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 18 Jan 2015 20:04:01 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 22:23:41 GMT]]></title><description><![CDATA[<p>Acho so.<br />
In dem Satz steht &quot;und&quot;, daher dachte ich dass du &quot;letzteres&quot; auf den ganzen Satz beziehst.<br />
OK, jetzt verstehe ich was du meinst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438309</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 18 Jan 2015 22:23:41 GMT</pubDate></item><item><title><![CDATA[Reply to template parameter is not of integral or enumeration type on Sun, 18 Jan 2015 23:00:17 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>In dem Satz steht &quot;und&quot;, daher dachte ich dass du &quot;letzteres&quot; auf den ganzen Satz beziehst.</p>
</blockquote>
<p>Ich hatte schon befürchtet dass jemand darauf anspringt. Macht auch Sinn, daher: Mea culpa.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438311</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 18 Jan 2015 23:00:17 GMT</pubDate></item></channel></rss>