Auto attributes for functions

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 19 20:11:00 PDT 2014


On Wednesday, 20 August 2014 at 01:38:53 UTC, uri wrote:
> Hi all,
>
> Bit new to D so this might be a very naive question...
>
> Can the compiler auto infer function attributes?
>
> I am often adding as many attributes as possible and use the 
> compiler to show me where they're not applicable and take them 
> away. It would be great if this could be achieved like so:
>
> auto function() @auto
> {}
>
> instead of manually writing:
>
> auto function() pure @safe nothrow @nogc const
> {}
>
> cheers,
> uri

Only if they're template functions.

//inferred as @safe pure nothrow @nogc
auto fun()() {}

//Compiler treats this is @system impure throwing @gc
//(if the latter three existed)
auto fun() {}

I think Andrei suggested in the past that functions with a return 
type of "auto" have attributes inferred for them as well, but 
some people were against it, and nobody's tried implementing it 
yet.


More information about the Digitalmars-d-learn mailing list