Revert attributes to their defaults with default keywords

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 9 04:11:00 PST 2015


On Fri, 09 Jan 2015 11:57:50 +0000
Daniel Kozak via Digitalmars-d <digitalmars-d at puremagic.com> 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
i've dreamt about similar feature for a long time! i was thinking about
"negative attributes" though (@canthrow, @virtual, etc), but your
solution seems to be better as it's not poluting language with new
attrs.

can it be used like this:

  final:
  nothrow:
    ...
    default void foo () { ... }
    ...

so only `foo` becomes default, but all other methods after `foo` are
`final nothrow`?

and can it be used like this:

  default void foo () nothrow { ... }

so `default` resets all attrs and then i can specify another set of
attrs inline?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150109/4fbe9897/attachment.sig>


More information about the Digitalmars-d mailing list