Attribute inference for auto functions?

deadalnix deadalnix at gmail.com
Wed Apr 17 00:58:41 PDT 2013


On Wednesday, 17 April 2013 at 07:04:16 UTC, Peter Alexander 
wrote:
> Often enough. I often find myself returning ranges, which are 
> almost invariably complex template types.
>
> And, to be honest, I would just like to use auto without being 
> locked into inferred attributes. It just feels wrong that these 
> things should be conflated, and I get the feeling we will 
> regret this later on when D starts to be used in larger 
> projects.

Note that this is consistent with many choice D made.

auto is a storage class. storage class usually stick to the 
function, not the return type :
const Foo bar(); // Error as const qualify bar and not Foo.

auto is about type inference. Attribute is part of the function 
type as much as it return type, and so it is expected that auto 
applied to a function infer its attributes and its return type.

The problem you are talking about is very real, but much broader 
than this auto thing. The problem is that you have no control on 
what the storage classes bind on.

Examples :
extern(C) void function() foo; // does extern binds to foo, foo's 
type or both ?
pure function() function() bar; // is bar a pure function ? is 
bar() pure ? Noth ? How to choose ?

Back to the subject, if auto bind to the function it must infers 
attributes, if it binds to the return type, it mustn't. And right 
now, storage class bind to the function.


More information about the Digitalmars-d mailing list