Auto attributes for functions

ed via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 20 03:18:13 PDT 2014


On Wednesday, 20 August 2014 at 09:13:15 UTC, Jonathan M Davis 
via Digitalmars-d-learn wrote:
> On Wed, 20 Aug 2014 01:38:52 +0000
> uri via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> 
> 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
>> {}
>
> Currently, just templated functions get their attributes 
> inferred. The biggest
> problem with inferring them for all functions is that you can 
> declare a
> function without defining it in the same place (e.g. if you're 
> using .di
> files), in which case the compiler has no function body to use 
> for attribute
> inferrence.
>
> There have been discussions on ways to reasonably infer 
> attributes under more
> circumstances, but nothing has come of them yet. However, I'd 
> expect that
> there will be at least some improvements to the situation at 
> some point given
> that there is a general consensus that while the attributes are 
> quite useful,
> it's also rather annoying to have to keep typing them all.
>
> - Jonathan M Davis

Thanks guys for the info.

/uri


More information about the Digitalmars-d-learn mailing list