Alias this and opDispatch override

Domain dont_email at empty.com
Fri Sep 7 02:22:58 UTC 2018


The following code fail to compile:

enum KeyMod : int
{
     LCtrl  = 1 << 0,
     RCtrl  = 1 << 1,
     Ctrl   = LCtrl | RCtrl,
}

struct Flags(E)
{
public:
     BitFlags!(E, Yes.unsafe) flags;
     alias flags this;

     bool opDispatch(string name)() const
     if (__traits(hasMember, E, name))
     {
         enum e = __traits(getMember, E, name);
         return (mValue & e) != 0;
     }
}

Flags!KeyMod keys;
keys.LCtrl = true;
assert(keys.Ctrl);

Error: no property LCtrl for type Flags!(KeyMod)
Error: no property Ctrl for type Flags!(KeyMod)


More information about the Digitalmars-d-learn mailing list