<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Using C++11 auto and decltype</title>
	<link>https://codesynthesis.com/~boris/blog//2012/08/14/using-cxx11-auto-decltype/</link>
	<description>Boris Kolpackov's blog about software</description>
	<pubDate>Sat, 13 Jun 2026 11:00:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: Dmitri</title>
		<link>https://codesynthesis.com/~boris/blog//2012/08/14/using-cxx11-auto-decltype/#comment-2291</link>
		<author>Dmitri</author>
		<pubDate>Wed, 15 Aug 2012 16:39:04 +0000</pubDate>
		<guid>https://codesynthesis.com/~boris/blog//2012/08/14/using-cxx11-auto-decltype/#comment-2291</guid>
		<description>In addition to what was said in this article, I think the great benefit of keyword `auto` is its use follow the DRY principle. It also allows to capture the intention of coder more accurately. Consider:

int f() { return 42; }

int x = f(); // In this line, what we really want is a variable x of type whatever f() returns, which we have to write explicitly as int, violating DRY

auto y = f(); // This does not violate DRY, and matches the intention of having variable x of type whatever f() returns

That said, all these auto and decltype keywords make it more mandatory to have a good IDE with type induction. While previously you could use notepad and Search to find the type of a given variable, now that process becomes more convoluted. Instead, your IDE should be able to tell you what the type of any variable is right away.</description>
		<content:encoded><![CDATA[<p>In addition to what was said in this article, I think the great benefit of keyword `auto` is its use follow the DRY principle. It also allows to capture the intention of coder more accurately. Consider:</p>
<p>int f() { return 42; }</p>
<p>int x = f(); // In this line, what we really want is a variable x of type whatever f() returns, which we have to write explicitly as int, violating DRY</p>
<p>auto y = f(); // This does not violate DRY, and matches the intention of having variable x of type whatever f() returns</p>
<p>That said, all these auto and decltype keywords make it more mandatory to have a good IDE with type induction. While previously you could use notepad and Search to find the type of a given variable, now that process becomes more convoluted. Instead, your IDE should be able to tell you what the type of any variable is right away.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Boris Kolpackov</title>
		<link>https://codesynthesis.com/~boris/blog//2012/08/14/using-cxx11-auto-decltype/#comment-2290</link>
		<author>Boris Kolpackov</author>
		<pubDate>Tue, 14 Aug 2012 19:24:24 +0000</pubDate>
		<guid>https://codesynthesis.com/~boris/blog//2012/08/14/using-cxx11-auto-decltype/#comment-2290</guid>
		<description>Jesse, only if auto is not used to form a reference the top-level const-qualifier is stripped. I know this is a lot of "if-this-then-that" special cases. That's why I like the idea of mentally re-writing a statement with auto into a function template. Consider:

&lt;pre&gt;&lt;br /&gt;
template &#60;typename T&#62;&lt;br /&gt;
void g1 (T x);&lt;br /&gt;
&#160;&lt;br /&gt;
template &#60;typename T&#62;&lt;br /&gt;
void g2 (T&#38; x);&lt;br /&gt;
&#160;&lt;br /&gt;
g1 (f ()); // T is int (not const int), x is int&lt;br /&gt;
g2 (f ()); // T is const int, x is const int&#38;&lt;br /&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Jesse, only if auto is not used to form a reference the top-level const-qualifier is stripped. I know this is a lot of &#8220;if-this-then-that&#8221; special cases. That&#8217;s why I like the idea of mentally re-writing a statement with auto into a function template. Consider:</p>
<pre>
template &lt;typename T&gt;
void g1 (T x);
&nbsp;
template &lt;typename T&gt;
void g2 (T&amp; x);
&nbsp;
g1 (f ()); // T is int (not const int), x is int
g2 (f ()); // T is const int, x is const int&amp;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse</title>
		<link>https://codesynthesis.com/~boris/blog//2012/08/14/using-cxx11-auto-decltype/#comment-2289</link>
		<author>Jesse</author>
		<pubDate>Tue, 14 Aug 2012 18:30:13 +0000</pubDate>
		<guid>https://codesynthesis.com/~boris/blog//2012/08/14/using-cxx11-auto-decltype/#comment-2289</guid>
		<description>You first say this:

const int&#38; f3 ();
auto a3 = f3 (); // a1 is int

Then you say that

const int&#38; f ();
auto&#38; x = f (); // auto -&#62; const int, x is const int&#38;

Wouldn't this imply that:
auto&#38; x = f (); // auto -&#62; int, x is int&#38;</description>
		<content:encoded><![CDATA[<p>You first say this:</p>
<p>const int&amp; f3 ();<br />
auto a3 = f3 (); // a1 is int</p>
<p>Then you say that</p>
<p>const int&amp; f ();<br />
auto&amp; x = f (); // auto -&gt; const int, x is const int&amp;</p>
<p>Wouldn&#8217;t this imply that:<br />
auto&amp; x = f (); // auto -&gt; int, x is int&amp;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
