<?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[std::common_type]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich war der Meinung, dass std::common_type bei Integer-Typen den Typ liefert, den auch eine Verknüpfung der Datentypen mit einem Operator (z.B. + ) liefert.</p>
<p>So hatte ich auch dies (<a href="http://en.cppreference.com/w/cpp/types/common_type" rel="nofollow">http://en.cppreference.com/w/cpp/types/common_type</a>) verstanden:</p>
<p><a href="http://cppreference.com" rel="nofollow">cppreference.com</a>  schrieb:</p>
<blockquote>
<p>For arithmetic types, the common type may also be viewed as the type of the (possibly mixed-mode) arithmetic expression such as T0() + T1() + ... + Tn().</p>
</blockquote>
<p>Unter Visual Studio 2013 erhalte ich mit diesem Code</p>
<pre><code>#include &lt;type_traits&gt;
#include &lt;iostream&gt;

int main( void )
{
	typedef signed char signed_char_t;
	std::cout &lt;&lt; typeid( std::common_type&lt; signed_char_t, signed_char_t &gt;::type ).name() &lt;&lt; std::endl;
	std::cout &lt;&lt; typeid( decltype( signed_char_t{ 127 } + signed_char_t{ 127 } ) ).name() &lt;&lt; std::endl;
}
</code></pre>
<p>folgende Ausgabe</p>
<p>console schrieb:</p>
<blockquote>
<p>signed char<br />
int</p>
</blockquote>
<p>Verstehe ich std::common_type falsch oder ist die Ausgabe des Programms falsch? Ich hätte erwartet, dass beide Typen gleich sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/322993/std-common_type</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 13:41:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322993.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Jan 2014 08:54:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::common_type on Wed, 15 Jan 2014 08:54:31 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich war der Meinung, dass std::common_type bei Integer-Typen den Typ liefert, den auch eine Verknüpfung der Datentypen mit einem Operator (z.B. + ) liefert.</p>
<p>So hatte ich auch dies (<a href="http://en.cppreference.com/w/cpp/types/common_type" rel="nofollow">http://en.cppreference.com/w/cpp/types/common_type</a>) verstanden:</p>
<p><a href="http://cppreference.com" rel="nofollow">cppreference.com</a>  schrieb:</p>
<blockquote>
<p>For arithmetic types, the common type may also be viewed as the type of the (possibly mixed-mode) arithmetic expression such as T0() + T1() + ... + Tn().</p>
</blockquote>
<p>Unter Visual Studio 2013 erhalte ich mit diesem Code</p>
<pre><code>#include &lt;type_traits&gt;
#include &lt;iostream&gt;

int main( void )
{
	typedef signed char signed_char_t;
	std::cout &lt;&lt; typeid( std::common_type&lt; signed_char_t, signed_char_t &gt;::type ).name() &lt;&lt; std::endl;
	std::cout &lt;&lt; typeid( decltype( signed_char_t{ 127 } + signed_char_t{ 127 } ) ).name() &lt;&lt; std::endl;
}
</code></pre>
<p>folgende Ausgabe</p>
<p>console schrieb:</p>
<blockquote>
<p>signed char<br />
int</p>
</blockquote>
<p>Verstehe ich std::common_type falsch oder ist die Ausgabe des Programms falsch? Ich hätte erwartet, dass beide Typen gleich sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2377358</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2377358</guid><dc:creator><![CDATA[void*]]></dc:creator><pubDate>Wed, 15 Jan 2014 08:54:31 GMT</pubDate></item><item><title><![CDATA[Reply to std::common_type on Wed, 15 Jan 2014 10:38:49 GMT]]></title><description><![CDATA[<p>Die Ausgabe des Programms ist, soweit ich das sehen kann, richtig, die Beschreibung auf <a href="http://http" rel="nofollow">http://http</a>://en.cppreference.com/w/cpp/types/common_type stimmt eben nur in erster Näherung. <code>std::common_type&lt;A, B&gt;::type</code> entspricht <code>decltype(true ? std::declval&lt;A&gt;() : std::declval&lt;B&gt;())</code> und das liefert in dem Fall etwas anderes, da keine Integral Promotions durchgeführt werden wie beim + Operator...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2377399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2377399</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Wed, 15 Jan 2014 10:38:49 GMT</pubDate></item><item><title><![CDATA[Reply to std::common_type on Wed, 15 Jan 2014 12:13:33 GMT]]></title><description><![CDATA[<p>N3797 §5.16/3 schrieb:</p>
<blockquote>
<p>Lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are performed on the second and third operands.<br />
/After those conversions, one of the following shall hold:</p>
<p>— <strong>The second and third operands have the same type; the result is of that type.</strong> If the operands have class type, the result is a prvalue temporary of the result type, which is copy-initialized from either the second operand or the third operand depending on the value of the first operand.<br />
— The second and third operands have arithmetic or enumeration type; the usual arithmetic conversions are performed to bring them to a common type, and the result is of that type.</p>
</blockquote>
<p>Der zweite Punkt greift nun erst, wenn es zwar zwei Skalare sind, aber unterschiedlichen Typ haben. Das ist hier nicht der Fall.</p>
<p>Btw:</p>
<pre><code>decltype( signed_char_t{ 127 } + signed_char_t{ 127 } )
// &lt;=&gt;
decltype( signed_char_t{} + signed_char_t{} )
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2377412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2377412</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 15 Jan 2014 12:13:33 GMT</pubDate></item><item><title><![CDATA[Reply to std::common_type on Thu, 16 Jan 2014 11:55:42 GMT]]></title><description><![CDATA[<p>Vielen Dank für Eure Antworten!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2377585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2377585</guid><dc:creator><![CDATA[void*]]></dc:creator><pubDate>Thu, 16 Jan 2014 11:55:42 GMT</pubDate></item></channel></rss>