Revert attributes to their defaults with default keywords

Meta via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 9 18:47:00 PST 2015


On Friday, 9 January 2015 at 14:26:26 UTC, aldanor wrote:
> It could work both ways at the same time.
>
> Maybe even something like "default(pred) final(pred) nothrow" 
> --> if pred is compile-time-true, reset all attributes and then 
> add final/nothrow; if it's compile-time-false, disable final 
> and enable nothrow.

@disable is also currently a keyword.

pure nothrow @safe @nogc immutable
Test
{
     //doSomething is nothrow @safe @nogc immutable
     @disable(pure) void doSomething() {}

     //getAnInt is pure @nogc immutable
     @disable(nothrow, @safe) int getAnInt() {}

     //typeof(n) == int
     @disable(immutable) int n;
}

This is also useful for templated functions, methods, etc. It 
allows one to tell the compiler that the function in question 
should never have a particular attribute inferred for it.

//doSomethingElse will never be inferred as pure,
//but may be inferred as nothrow, @safe, or @nogc
@disable(pure) void doSomethingElse()() {}


More information about the Digitalmars-d mailing list