Negation of attributes (DIP 79)

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 2 09:49:09 PDT 2015


On 06/02/15 14:21, ketmar via Digitalmars-d wrote:
> On Tue, 02 Jun 2015 11:50:15 +0000, Namespace wrote:
> 
>> For me it looks ugly. But I would prefer final(false) instead of !final.
> 
> this opens a can of worms. should this be accepted too:
>   enum doItFinal = false;
>   final(doItFinal)
> ?
> 
> or even
>   final(someFunnyTemplate!(with_, args, andOtherTemplate!"too"))
> ?

[I'd assumed it was a rhetorical question, but after reading
 some of the followups...]

Of course.


Note that user defined attributes already work like that. This is
a working D program, that uses GDC-specific extensions:

   import gcc.attribute;
   enum inl(alias B) = attribute(B?"forceinline":"noinline");
   
   @inl!(1) int f() { return 1; }
   @inl!(2+2==5) int g() { return 2; }
   enum e = g()-f()*2;
   @inl!e int i() { return 3; }
   int main() { return f()+g()+i(); }

The only alternative would be to force wrapping the whole (function)
definition in a mixin statement -- that is not a practical solution
and not scalable at all. You end up with multiple layers of string
mixins and code written inside (nested!) string literals.

D has enough unnecessary special cases as it is (like built-in types
being special).

artur


More information about the Digitalmars-d mailing list