Proposal: __not(keyword)

Adam D. Ruppe destructionator at gmail.com
Fri Sep 14 18:06:55 UTC 2018


Here's the simple idea: __not(anything) just turns off whatever 
`anything` does in the compiler.

__not(final) void foo() {} // turns off the final flag (if it is 
set)
__not(@nogc) void foo() {} // turns off the @nogc flag (if it is 
set)

__not(const)(int) a; // not const

All it does is invert the flags; the implementation would be like 
`flags &= ~WHATEVER;` so unless it was already set, it does 
nothing and does not check for contradictions.


const:
    int b; // const
   __not(const)(int) a; // not const
immutable:
    int c; // immutable int
    __not(const)(int) a; // still immutable int; there was no 
const set to turn off.


It also affects attrs brought through definitions though:

shared class foo {
    int a; // automatically shared cuz of the above line of code
    __not(shared) int b; // no longer shared
}



This is just a generic way to get the flipped attributes WHICH WE 
DESPERATELY NEED IN ALL SITUATIONS and I don't want to argue over 
keywords line impure and whatever __not(shared) would be called 
etc.


More information about the Digitalmars-d mailing list