Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11: Standard ref for action of `auto` on const and reference types

Tags:

c++

c++11

Suppose I have a type T:

typedef ... T;

and then I have these functions:

T f11();
T& f12();
T&& f13();
const T f21();
const T& f22();
const T&& f23();

and then call them like this:

auto x11 = f11();
auto x12 = f12();
auto x13 = f13();
auto x21 = f21();
auto x22 = f22();
auto x23 = f23();

From which sections/clauses of the C++11 standard can it be deduced the equivalent non-auto declarations of x11..x23?

like image 468
Andrew Tomazos Avatar asked Sep 03 '12 05:09

Andrew Tomazos


1 Answers

It is in §7.1.6.4 auto specifier. In your examples of function return types, the rules of template argument deduction apply.

Paraquoting the relevant example from the standard:

const auto &i = expr;

The type of i is the deduced type of the parameter X in the call f(expr) of the following invented function template:

template <class AUTO> void f(const AUTO& X);

So in your examples, the types of all your variables x11 to x23 are deduced as T.

like image 190
juanchopanza Avatar answered Sep 30 '22 01:09

juanchopanza