Idea to verify virtual/final methods

bearophile bearophileHUGS at lycos.com
Tue Jun 4 06:15:39 PDT 2013


Jacob Carlborg:

> struct virtual {} // the UDA
>
> class Foo
> {
>     void a () {} // static assert, not declared as @virtual
>     @virtual void b () {} // ok
>     @virtual final void c () {} // static assert, declared as 
> final and @virtual
>     final d () {} // ok
> }
>
> checkVirtual!(Foo);

My original purposes for UDAs was to extend the type system, as
you have essentially done here. But to do that well enough the
attributes need to be more active.

An idea:

struct Small(T) if (T.sizeof <= 16) {}

@Small struct Bar {
       int x;
}


Here Small get instantiated with T == Bar, and its constraint
performs the active compile-time test.

Bye,
bearophile


More information about the Digitalmars-d mailing list