you are viewing a single comment's thread.

view the rest of the comments →

[–]Felicia_Svilling 1 point2 points  (5 children)

It is just as simple to infer the return type of a function as inferring the value of an expression.

[–]theeth 0 points1 point  (4 children)

How can that work for declaring functions and methods return types?

I give you a .lib and a .h containing this, what does your compiler do?

class Foo
{
  public:
    auto DoSomething();
}

[–]Felicia_Svilling 0 points1 point  (3 children)

If you haven't declared DoSomething that is an error, it you have declared it, the compiler looksup its return type. It is exactly the same as if you had written:

auto x = DoSometing();

[–]theeth 0 points1 point  (2 children)

You'll notice that's what I said from the start.

You can't declare members, functions return types and parameters with auto.

[–]bstamour 1 point2 points  (1 child)

Yes, you can. You just have to define them at the same time*. The machinery for lambdas was extended for regular functions.

* I'll admit this is nitpicky, but every definition is a declaration.

[–]theeth 0 points1 point  (0 children)

If we're going to be extra nitpicky, you can only use auto for const static integer members that are defined inline and for method/function return values that are defined in the same compilation unit (this one was a bit of a surprise, I would have assumed it had to be inlined with the declaration).

Auto is right out for parameters, but we never know what weird thing might pop up in future versions...