5

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?

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319

1 Answers1

5

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.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480