<?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[lambda und std::is_constructable]]></title><description><![CDATA[<p>Hallo,</p>
<p>angenommen ich hab folgenden Code:</p>
<pre><code>#include &lt;iostream&gt;

int main()
{
	int i = 0;
	auto lambda = [=]{ return i; };

	std::cout &lt;&lt; std::boolalpha;
	std::cout &lt;&lt; std::is_constructible&lt;decltype(lambda), int&gt;::value &lt;&lt; '\n'; // true
}
</code></pre>
<p>dann sagt mir std::is_contructable ja dass ich das lambda mit einem int erstellen darf... Wenn ich dann aber sowas schreibe:</p>
<pre><code>decltype(lambda) test(i);
</code></pre>
<p>dann erhalte ich einen Fehler <em>&quot;error C3497: Es kann keine Instanz eines Lambdas erstellt werden&quot;</em>.</p>
<p>Aber per:</p>
<pre><code>auto test = lambda;
</code></pre>
<p>kann ich doch eine solche Instanz erstellen, oder nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327718/lambda-und-std-is_constructable</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Jul 2026 16:54:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327718.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 30 Aug 2014 19:44:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to lambda und std::is_constructable on Sat, 30 Aug 2014 19:44:09 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>angenommen ich hab folgenden Code:</p>
<pre><code>#include &lt;iostream&gt;

int main()
{
	int i = 0;
	auto lambda = [=]{ return i; };

	std::cout &lt;&lt; std::boolalpha;
	std::cout &lt;&lt; std::is_constructible&lt;decltype(lambda), int&gt;::value &lt;&lt; '\n'; // true
}
</code></pre>
<p>dann sagt mir std::is_contructable ja dass ich das lambda mit einem int erstellen darf... Wenn ich dann aber sowas schreibe:</p>
<pre><code>decltype(lambda) test(i);
</code></pre>
<p>dann erhalte ich einen Fehler <em>&quot;error C3497: Es kann keine Instanz eines Lambdas erstellt werden&quot;</em>.</p>
<p>Aber per:</p>
<pre><code>auto test = lambda;
</code></pre>
<p>kann ich doch eine solche Instanz erstellen, oder nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415493</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415493</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Sat, 30 Aug 2014 19:44:09 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sat, 30 Aug 2014 19:59:56 GMT]]></title><description><![CDATA[<p>Ganz einfach: Die Implementierung von <code>std::is_constructible</code> wird wahrscheinlich einen Bug haben nachdem auch private Konstruktoren berücksichtigt werden. Eigentlich sollte expression-SFINAE o.ä. verwendet werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415494</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 30 Aug 2014 19:59:56 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sat, 30 Aug 2014 20:13:03 GMT]]></title><description><![CDATA[<p>Ach so Ok, wenn das ein Bug ist dann passts ja.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415496</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Sat, 30 Aug 2014 20:13:03 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sat, 30 Aug 2014 20:17:28 GMT]]></title><description><![CDATA[<p>Das vom GCC generierte Programm hat die richtige Ausgabe, nämlich &quot;false&quot;. Der nutzt eben SFINAE in seiner Implementierung von <code>__is_nary_constructible</code> .</p>
<p>Der closure-Typ sieht (unoptimiert) wahrscheinlich etwa so aus:</p>
<pre><code>class __lambda654 // irgendein Name
{
    int i;

    __lambda654(int i) : i(i){}

public:

    // implizit generierter Kopierkonstruktor

    int operator()() const {return i;}
};
</code></pre>
<p>VC++ eben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415498</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415498</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 30 Aug 2014 20:17:28 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sat, 30 Aug 2014 20:45:43 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Ganz einfach: Die Implementierung von <code>std::is_constructible</code> wird wahrscheinlich einen Bug haben nachdem auch private Konstruktoren berücksichtigt werden. Eigentlich sollte expression-SFINAE o.ä. verwendet werden.</p>
</blockquote>
<p>Ich glaub ehrlich gesagt nicht, dass is_constructible private Ctors berücksichtigt.<br />
Da müsste man sich ja schon anstrengen um das hinzukriegen.<br />
Laut der Fehlermeldung glaub ich eher, dass der Ctor public ist und der Compiler einfach eine Fehlermeldung ausgibt, sobald man ihn aufrufen möchte.<br />
Denn konstruiert sieht sie auf jeden Fall aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415500</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415500</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 30 Aug 2014 20:45:43 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sun, 31 Aug 2014 09:29:11 GMT]]></title><description><![CDATA[<blockquote>
<p>Da müsste man sich ja schon anstrengen um das hinzukriegen.</p>
</blockquote>
<p>Ich habe vollstes Vertrauen in VC++.</p>
<blockquote>
<p>Laut der Fehlermeldung glaub ich eher, dass der Ctor public ist und der Compiler einfach eine Fehlermeldung ausgibt, sobald man ihn aufrufen möchte.</p>
</blockquote>
<p>Ja, plausibel. Wie sieht denn die Implementierung von <code>is_constructible</code> beim VC++ aus? Laut deiner Theorie müsste durch ein Intrinsic implementiert sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415511</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 31 Aug 2014 09:29:11 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sun, 31 Aug 2014 09:53:41 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Laut deiner Theorie müsste durch ein Intrinsic implementiert sein.</p>
</blockquote>
<p>Ist es. Wer schreibt den Bug report?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415512</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Sun, 31 Aug 2014 09:53:41 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sun, 31 Aug 2014 09:59:50 GMT]]></title><description><![CDATA[<p>Du natürlich :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415514</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 31 Aug 2014 09:59:50 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Sun, 31 Aug 2014 10:03:41 GMT]]></title><description><![CDATA[<p>Nö. Ich bin mit dem Template- und C++11-Zeugs zu wenig vertraut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415515</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Sun, 31 Aug 2014 10:03:41 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Fri, 12 Sep 2014 17:56:44 GMT]]></title><description><![CDATA[<p>Und ich werde mich nicht bei Microsoft registrieren.</p>
<p>Schreib sowas:</p>
<p>This code:</p>
<pre><code>#include &lt;type_traits&gt;

int main()
{
    int i = 0;
    auto lambda = [=]{ return i; };
    static_assert( std::is_constructible&lt;decltype(lambda), int&gt;::value, &quot;&quot; );
}
</code></pre>
<p>shouldn't compile, because declaring an object like so:</p>
<pre><code>decltype(lambda) d(i);
</code></pre>
<p>doesn't compile and isn't well-formed (which is exactly the condition that <code>is_constructible</code> should examine).</p>
<p>The above code does compile though.</p>
<p>It seems the implementation of <code>std::is_constructible</code> (or the intrinsic <code>__is_constructible</code> , respectively) is bugged and doesn't consider the compiler magic that happens to prevent the programmer from constructing a closure object in the aforementioned way.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415518</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 12 Sep 2014 17:56:44 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Mon, 01 Sep 2014 10:44:20 GMT]]></title><description><![CDATA[<p>Hallo happystudent,</p>
<p>happystudent schrieb:</p>
<blockquote>
<p>... Wenn ich dann aber sowas schreibe:</p>
<pre><code>decltype(lambda) test(i);
</code></pre>
<p>dann erhalte ich einen Fehler <em>&quot;error C3497: Es kann keine Instanz eines Lambdas erstellt werden&quot;</em>.</p>
</blockquote>
<p>Der VC++-Compiler scheint hier den Returnwert der lamda-Funktion und die lambda-Funktion selbst durcheinander zu würfeln.<br />
So übersetzt z.B.:</p>
<pre><code>decltype(lambda) test = i;
</code></pre>
<p>Wenn man aber schreibt:</p>
<pre><code>decltype(lambda) test = irgendeinInt;
</code></pre>
<p>dann gibt</p>
<pre><code>cout &lt;&lt; &quot;test() = &quot; &lt;&lt; test() &lt;&lt; endl;
</code></pre>
<p>stets den Wert von 'irgendeinInt' statt den von 'i' aus.</p>
<p>Ein Hinweis darauf, dass der VC++-Compiler decltype(lambda) tatsächlich fälschlicherweise als int interpretiert, liefert auch:</p>
<pre><code>decltype(lambda) test = 0.12;
</code></pre>
<p>mit der Warnung: &quot; <code>warning C4244: 'argument' : conversion from 'double' to 'const int', possible loss of data</code> &quot;</p>
<p>Es gibt noch viel zu tun ...<br />
Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415640</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Mon, 01 Sep 2014 10:44:20 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Mon, 01 Sep 2014 11:11:50 GMT]]></title><description><![CDATA[<p>Werner Salomon schrieb:</p>
<blockquote>
<p>Wenn man aber schreibt: […] dann gibt […] stets den Wert von 'irgendeinInt' statt den von 'i' aus.</p>
</blockquote>
<p>Und was genau soll daran verwunderlich sein? Das ist das erwartete Verhalten. Der closure-Typ hat einen Konstruktor der den Member <code>i</code> initialisiert.</p>
<blockquote>
<p>Ein Hinweis darauf, dass der VC++-Compiler decltype(lambda) tatsächlich fälschlicherweise als int interpretiert, liefert auch: […]</p>
</blockquote>
<p>Jeder Compiler gibt dir eine Warnung wenn du versuchst eine Ganzzahl mit einem Fließkomma-Literal zu initialisieren - in diesem Fall ist der <code>int</code> der Konstruktorparameter.</p>
<p>Wir können aber deine Theorie per</p>
<pre><code>static_assert( std::is_convertible&lt;decltype(lambda), int&gt;::value, &quot;&quot; );
</code></pre>
<p>überprüfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415642</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 01 Sep 2014 11:11:50 GMT</pubDate></item><item><title><![CDATA[Reply to lambda und std::is_constructable on Mon, 01 Sep 2014 12:40:44 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Werner Salomon schrieb:</p>
<blockquote>
<p>Wenn man aber schreibt: […] dann gibt […] stets den Wert von 'irgendeinInt' statt den von 'i' aus.</p>
</blockquote>
<p>Und was genau soll daran verwunderlich sein? Das ist das erwartete Verhalten.</p>
</blockquote>
<p>ich habe das nicht erwartet <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>Arcoth schrieb:</p>
<blockquote>
<p>Der closure-Typ hat einen Konstruktor der den Member <code>i</code> initialisiert.</p>
</blockquote>
<p>.. so scheint es zu sein, aber wo bitteschön in den Weiten des Standards ist das beschrieben?</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2415652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2415652</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Mon, 01 Sep 2014 12:40:44 GMT</pubDate></item></channel></rss>