<?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[type_trait zum überprüfen ob typ komplett definiert ist]]></title><description><![CDATA[<p>Hi,</p>
<p>ich brauche ein type_trait zum überprüfen ob ein Typ komplett definiert ist oder nicht. Hat jemand ein code snippet dafür?</p>
<pre><code>class A;

static_assert(is_complete&lt;A&gt;::value, &quot;type is not defined&quot;);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/331385/type_trait-zum-überprüfen-ob-typ-komplett-definiert-ist</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 16:47:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331385.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Feb 2015 22:51:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Wed, 25 Feb 2015 22:51:20 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich brauche ein type_trait zum überprüfen ob ein Typ komplett definiert ist oder nicht. Hat jemand ein code snippet dafür?</p>
<pre><code>class A;

static_assert(is_complete&lt;A&gt;::value, &quot;type is not defined&quot;);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2444377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444377</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Wed, 25 Feb 2015 22:51:20 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Wed, 25 Feb 2015 23:21:03 GMT]]></title><description><![CDATA[<p>Wenns nur um das <code>static_assert</code> geht, dann gibt's da ne mehr oder weniger einfache Möglichkeit:</p>
<pre><code class="language-cpp">// Aus boost::checked_delete():

    // intentionally complex - simplification causes regressions
    typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
    (void) sizeof(type_must_be_complete);
</code></pre>
<p>Ich vermute allerdings ein <code>static_assert(sizeof(T) &gt; 0)</code> müsste auch reichen.</p>
<p>Per Type-Trait kann es auf jeden Fall nicht gehen. Denn der Wert von <code>type_traits&lt;T&gt;::xxx</code> muss ja identisch sein, egal an welcher Stelle im Programm man den Wert &quot;anguckt&quot;.<br />
Andernfalls kämen da sicherliche viele Würmer aus der Dose gekrochen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444380</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 25 Feb 2015 23:21:03 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Thu, 26 Feb 2015 12:16:27 GMT]]></title><description><![CDATA[<p>sizeof darf auf unvollstaendige Typen gar nicht angewandt werden. Daher schlage ich</p>
<pre><code>template &lt;class, class=void&gt; struct is_complete : std::false_type {};
template &lt;class T&gt;
struct is_complete&lt;T, decltype(void(sizeof(T)))&gt; : std::true_type {};
</code></pre>
<p>vor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444430</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 26 Feb 2015 12:16:27 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Thu, 26 Feb 2015 12:40:05 GMT]]></title><description><![CDATA[<p>Und was soll das bringen?</p>
<p>BTW: dass <code>sizeof</code> auf unvollständige Typen nicht angewendet werden darf ist ja auch das Grund dass und der Mechanismus über den der aus der Boost zitierte Code funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444431</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 26 Feb 2015 12:40:05 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Thu, 26 Feb 2015 22:43:00 GMT]]></title><description><![CDATA[<p>@Arcoth<br />
Funktioniert, klasse!<br />
<a href="https://ideone.com/Z2XpR7" rel="nofollow">https://ideone.com/Z2XpR7</a></p>
<p>Kannst du bitte kurz erklären wie das funktioniert?</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/13960">@hustbaer</a><br />
ich wollte halt gern ein type traits haben, der dann nicht zwangsläufig in ein compile timer error mündet.</p>
<p>Komisches kommentar aus dem boost code:</p>
<blockquote>
<p>// intentionally complex - simplification causes regressions</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2444484</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444484</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Thu, 26 Feb 2015 22:43:00 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Thu, 26 Feb 2015 22:59:39 GMT]]></title><description><![CDATA[<p>@Arcoth: Ahm. Wie soll das funktionieren wenn in einer TU der betreffende Typ erst an Stelle x passend instantiiert wird du aber <code>is_complete</code> vorher und nachher auswertest?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444486</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444486</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Thu, 26 Feb 2015 22:59:39 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Thu, 26 Feb 2015 23:25:28 GMT]]></title><description><![CDATA[<p>Nash26 schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/13960">@hustbaer</a><br />
ich wollte halt gern ein type traits haben, der dann nicht zwangsläufig in ein compile timer error mündet.</p>
<p>Komisches kommentar aus dem boost code:</p>
<blockquote>
<p>// intentionally complex - simplification causes regressions</p>
</blockquote>
</blockquote>
<p>Das heisst dass es absichtlich so kompliziert gemacht wurde, weil einfachere Varianten mit manchen Compilern nicht funktionieren.<br />
Regression = Rückschritt = wenn man nen Fehler hat bei etwas was schonmal funktioniert hat.</p>
<p>D.h. da stand vermutlich die komplizierte Version und alles war gut.<br />
Und dann hat sie jmd. vereinfacht, und alles war nicht mehr gut.<br />
Und dann wurde wieder die komplizierte Version reingeschrieben, mit diesem Kommentar dazu, damit sie der nächste Herr Schlau nicht wieder vereinfacht.</p>
<p>Wobei das auch ne reichlich alte Boost Version ist wo ich das raus habe. Wie die aktuellen aussieht weiss ich nicht.</p>
<p>----</p>
<p>Ansonsten... Ich hab die Variante von Arcoth 'nu auch endlich verstanden. Hab' aber keine Ahnung ob das laut Standard funktionieren muss, da ich net weiss ob <code>sizeof(NotFullyDefined)</code> Fehler laut Standard für SFINAE gelten müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444492</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444492</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 26 Feb 2015 23:25:28 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Fri, 27 Feb 2015 07:15:12 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/8250">@swordfish</a></p>
<p>Da ist in der tat etwas nicht ganz koscher:<br />
<a href="https://ideone.com/I4EK8V" rel="nofollow">https://ideone.com/I4EK8V</a></p>
<p>Nachdem ich den Typ definiert habe, bekomme ich trotzdem eine Fehlermeldung..<br />
Ich hätte jetzt erwartet das ich keinen Fehler mehr bekomme.</p>
<p>@Arcoth<br />
Was sagst du dazu?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444514</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Fri, 27 Feb 2015 07:15:12 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Fri, 27 Feb 2015 07:33:02 GMT]]></title><description><![CDATA[<blockquote>
<p>BTW: dass <code>sizeof</code> auf unvollständige Typen nicht angewendet werden darf ist ja auch das Grund dass und der Mechanismus über den der aus der Boost zitierte Code funktioniert.</p>
</blockquote>
<p>... ich weiß. Habe ich etwas widersprüchliches behauptet?</p>
<blockquote>
<p>Denn der Wert von <code>type_traits&lt;T&gt;::xxx</code> muss ja identisch sein, egal an welcher Stelle im Programm man den Wert &quot;anguckt&quot;.</p>
</blockquote>
<p>Ich glaube du meinst</p>
<p>[temp.point]/8 schrieb:</p>
<blockquote>
<p>A specialization for any template may have points of instantiation in multiple translation units. <strong>If two different points of instantiation give a template specialization different meanings according to the one definition rule (3.2), the program is ill-formed, no diagnostic required.</strong></p>
</blockquote>
<p>Das hält aber das Trait an einem bestimmten Punkt nicht auf. Verwendet man jedoch dieselbe Spezialisierung an mehreren Orten wird es ggf. sinnlos und kann auch das Programm ill-formed NDR machen, genauso wie das Verwenden innerhalb eines Headers der in mehreren ÜEs inkonsistent eingebunden wird.</p>
<blockquote>
<p>Was sagst du dazu?</p>
</blockquote>
<p>Ich nahm natürlich an dass das Trait für einen Typen jeweils nur für diese eine assertion verwendet wird. Denn ein Template wird pro Übersetzungseinheit nur einmal instantiiert. Du kannst</p>
<pre><code>template &lt;class, int, class=void&gt; struct is_complete : std::false_type {};
template &lt;class T, int i&gt;
struct is_complete&lt;T, i, decltype(void(sizeof(T)))&gt; : std::true_type {};

#define IS_COMPLETE(...) is_complete&lt;__VA_ARGS__, __COUNTER__&gt;::value
</code></pre>
<p>Probieren (<a href="https://ideone.com/ICYDqE" rel="nofollow">Demo</a>), aber Vorsicht ist geboten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444516</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 27 Feb 2015 07:33:02 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Fri, 27 Feb 2015 12:54:27 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Denn der Wert von <code>type_traits&lt;T&gt;::xxx</code> muss ja identisch sein, egal an welcher Stelle im Programm man den Wert &quot;anguckt&quot;.</p>
</blockquote>
<p>Ich glaube du meinst</p>
<p>[temp.point]/8 schrieb:</p>
<blockquote>
<p>A specialization for any template may have points of instantiation in multiple translation units. <strong>If two different points of instantiation give a template specialization different meanings according to the one definition rule (3.2), the program is ill-formed, no diagnostic required.</strong></p>
</blockquote>
</blockquote>
<p>Ja, das meine ich. Ich merk mir die jeweiligen Stellen nie, wie findest du das immer so schnell?</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Das hält aber das Trait an einem bestimmten Punkt nicht auf. Verwendet man jedoch dieselbe Spezialisierung an mehreren Orten wird es ggf. sinnlos und kann auch das Programm ill-formed NDR machen, genauso wie das Verwenden innerhalb eines Headers der in mehreren ÜEs inkonsistent eingebunden wird.</p>
</blockquote>
<p>Klar kann man es 1x wo verwenden. Aber wenn man es nur 1x irgendwo verwenden darf, und sonst nirgends, weil man sonst &quot;ill-formed&quot; bekommt ... pfuh. Sowas verwende ich nicht.<br />
Da verlasse ich mich lieber auf non-Standard Verhalten wie dass der Compiler bei <code>sizeof(NotFullyDefined)</code> einfach nen Fehler wirft, obwohl er es nicht müsste (Oder muss er es? So genau kenne ich den Standard nicht - keine Ahnung ob das ein &quot;diagnostic required&quot; Fall ist).</p>
<p>Und da mir kein anderer Grund einfällt wissen zu wollen ob irgend ein Typ &quot;fully defined&quot; ist, als im Falle dass nicht einen Fehler zu erzeugen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444544</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444544</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 27 Feb 2015 12:54:27 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Fri, 27 Feb 2015 17:35:44 GMT]]></title><description><![CDATA[<blockquote>
<p>Klar kann man es 1x wo verwenden. Aber wenn man es nur 1x irgendwo verwenden darf, und sonst nirgends, weil man sonst &quot;ill-formed&quot; bekommt ... pfuh. Sowas verwende ich nicht.</p>
</blockquote>
<p>Verständlich, ich würde es ggf. auch nicht tun.</p>
<blockquote>
<p>Oder muss er es?</p>
</blockquote>
<p>Er muss es</p>
<p>[expr.sizeof]/1 schrieb:</p>
<blockquote>
<p>The <code>sizeof</code> operator shall not be applied to an expression that has [..] incomplete type</p>
</blockquote>
<p>[intro.compliance]/1 schrieb:</p>
<blockquote>
<p>The set of <em>diagnosable rules</em> consists of all syntactic and semantic rules in this International Standard except for those rules containing an <strong>explicit notation that “no diagnostic is required”</strong> or which are described as resulting in “undefined behavior.”</p>
</blockquote>
<p>Obiges trifft also auch auf die <code>sizeof</code> constraints zu. Und damit muss die Implementierung mindestens eine diagnostic message ausgeben:</p>
<p>[intro.compliance]/(2.2) schrieb:</p>
<blockquote>
<p>If a program contains a violation of any diagnosable rule [..] <strong>a conforming implementation shall issue at least one diagnostic message.</strong></p>
</blockquote>
<p>Das kann theoretisch auch eine Warnung sein, aber für unvollständige Typen kann <code>sizeof</code> keinen sinnvollen Wert annehmen. Zumindest kenne ich keine Implementierung die das mit einer Warnung kompilieren würde.</p>
<p>I.e. die sicherste Lösung wäre einfach ein expression statement mit einem Kommentar zu schreiben:</p>
<pre><code>sizeof(A); /* If you get an error message here, A is not complete.
              Please provide a definition of A before this line. */
</code></pre>
<blockquote>
<p>wie findest du das immer so schnell?</p>
</blockquote>
<p>Entsprechende Suchbegriffe per Strg+F. Hier habe ich einfach bei Kapitel 14 angefangen nach ill-formed zu suchen, hatte das Zitat nach einigen Minuten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444570</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 27 Feb 2015 17:35:44 GMT</pubDate></item><item><title><![CDATA[Reply to type_trait zum überprüfen ob typ komplett definiert ist on Fri, 27 Feb 2015 17:50:03 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>I.e. die sicherste Lösung wäre einfach ein expression statement mit einem Kommentar zu schreiben:</p>
<pre><code>sizeof(A); /* If you get an error message here, A is not complete.
              Please provide a definition of A before this line. */
</code></pre>
</blockquote>
<p>Ich erinnere nochmal an das Kommentar im Boost Code<br />
<code>// intentionally complex - simplification causes regressions</code><br />
Ich glaub nicht dass das ein Scherz ist <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="😉"
    /><br />
=&gt; Einfach nur <code>sizeof(A);</code> wird ziemlich sicher nicht für alle Compiler reichen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444571</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444571</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 27 Feb 2015 17:50:03 GMT</pubDate></item></channel></rss>