<?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[decltype mit verschachtelten Funktionsaufrufen]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich frage ich mich, ob<br />
man in folgendem Code das decltype von baz_type kürzen kann:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;tuple&gt;

int main() {
	auto foo = []{return 1;};
	typedef decltype(foo()) foo_type;
	auto bar = [](const foo_type&amp;){return 'c';};
	typedef decltype(bar(foo())) bar_type;
	auto baz = [](const bar_type&amp;){return 1.0;};
	typedef decltype(baz(bar(foo()))) baz_type;
	auto quux = [](const baz_type&amp;){};
}
</code></pre>
<p>Muss man wirklich alle Funktionsaufrufe ineinanderschachteln oder kann ich das (mit Hilfe eines typedefs?) kürzen?</p>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/295026/decltype-mit-verschachtelten-funktionsaufrufen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 15:11:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/295026.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 05 Nov 2011 16:43:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to decltype mit verschachtelten Funktionsaufrufen on Sat, 05 Nov 2011 16:43:58 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich frage ich mich, ob<br />
man in folgendem Code das decltype von baz_type kürzen kann:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;tuple&gt;

int main() {
	auto foo = []{return 1;};
	typedef decltype(foo()) foo_type;
	auto bar = [](const foo_type&amp;){return 'c';};
	typedef decltype(bar(foo())) bar_type;
	auto baz = [](const bar_type&amp;){return 1.0;};
	typedef decltype(baz(bar(foo()))) baz_type;
	auto quux = [](const baz_type&amp;){};
}
</code></pre>
<p>Muss man wirklich alle Funktionsaufrufe ineinanderschachteln oder kann ich das (mit Hilfe eines typedefs?) kürzen?</p>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2140795</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2140795</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sat, 05 Nov 2011 16:43:58 GMT</pubDate></item><item><title><![CDATA[Reply to decltype mit verschachtelten Funktionsaufrufen on Sat, 05 Nov 2011 22:22:35 GMT]]></title><description><![CDATA[<p>Sieht jetzt vielleicht nicht kürzer aus, aber ist immerhin lineare statt quadratische Komplexität:</p>
<pre><code class="language-cpp">template&lt;typename T&gt; T creator();

int main()
{
    //...
    typedef decltype(baz(creator&lt;bar_type&gt;())) baz_type;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2140889</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2140889</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Sat, 05 Nov 2011 22:22:35 GMT</pubDate></item><item><title><![CDATA[Reply to decltype mit verschachtelten Funktionsaufrufen on Sun, 06 Nov 2011 08:49:54 GMT]]></title><description><![CDATA[<p>dafür gibt es std::declval. Mit std::declval&lt;T&gt;() kann man einen Ausdruck vom Typ T erzeugen zwecks Einsatz innerhalb von decltype. In welchem Header das definiert wird, weiß ich gerade nicht. Vielleicht &lt;utility&gt;? Es kann aber sein, dass Dein Compiler das noch nicht kennt.</p>
<p>Einen Ersatz kann man sich so bauen:</p>
<pre><code class="language-cpp">#include &lt;type_traits&gt;
template&lt;class T&gt;
typename std::add_rvalue_reference&lt;T&gt;::type declval();
</code></pre>
<p>wobei aber die tatsächliche Verwendung außerhalb von nicht-evaluierten Ausdrücken einen Fehler darstellt. add_rvalue_reference wird hier eingesetzt, um unvollständige und abstrakte Typen als auch void zu unterstützen. Lvalues kann man aber auch damit erzeugen. Beispiel: declval&lt;int&amp;&gt;() erzeugt ein Lvalue Ausdruck vom Typ int.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2140947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2140947</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 06 Nov 2011 08:49:54 GMT</pubDate></item><item><title><![CDATA[Reply to decltype mit verschachtelten Funktionsaufrufen on Sun, 06 Nov 2011 14:31:17 GMT]]></title><description><![CDATA[<p>Danke euch beiden! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24868">@krümelkacker</a>:<br />
Genau das habe ich gesucht. Mein Compiler (GCC 4.6.1) unterstützt es auch.</p>
<p>Auch mit utility als Header lagst du richtig:<br />
<a href="http://en.cppreference.com/w/cpp/utility/declval" rel="nofollow">http://en.cppreference.com/w/cpp/utility/declval</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2141116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2141116</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 06 Nov 2011 14:31:17 GMT</pubDate></item></channel></rss>