Revert attributes to their defaults with default keywords
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jan 9 04:21:02 PST 2015
On 1/9/15 6:57 AM, Daniel Kozak wrote:
> I often have code like this:
>
> class A {
> final:
> nothrow:
> ...
> some methods
> ...
> }
>
> Problem comes when I need add methods which for eg.: throws or need to
> be virtual.
>
> I can put them before final: but this is not perfect, because I prefer
> when methods are place in specific order (method abc call method asd so
> asd is bellow abc and so on).
>
> So today I download dmd source and make some small modification (only
> few lines) and this is the result:
>
> http://dpaste.dzfl.pl/472afc938397
Nice, but I don't like the fact that it bluntly returns all attributes
to default.
For example, if you need to remove the final attribute, but not nothrow,
I'm assuming it looks something like:
default nothrow void foo()
which doesn't read very well.
If we are going to do this, I'd rather see something like has been
suggested before -- parameterizing attributes:
final(false) -> remove final
This allows compile-time booleans to modify attributes in ways that are
extremely difficult in templates today.
-Steve
More information about the Digitalmars-d
mailing list