UnderscoreOpDispatcher

Mixin template mixing in an opDispatch redirecting calls to members whose names match the passed variable string but with an underscore prepended.

mixin template UnderscoreOpDispatcher () {}

Members

Functions

opDispatch
auto ref opDispatch(T value)
Undocumented in source. Be warned that the author may not have intended to support it.
opDispatch
auto opDispatch()
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

struct Foo
{
    int _i;
    string _s;
    bool _b;

    mixin UnderscoreOpDispatcher;
}

Foo f;
f.i = 42;       // f.opDispatch!"i"(42);
f.s = "hello";  // f.opDispatch!"s"("hello");
f.b = true;     // f.opDispatch!"b"(true);

assert(f.i == 42);
assert(f.s == "hello");
assert(f.b);
import dialect.defs;

struct Foo
{
    IRCEvent.Type[] _acceptedEventTypes;
    alias _onEvent = _acceptedEventTypes;
    bool _verbose;
    bool _chainable;

    mixin UnderscoreOpDispatcher;
}

auto f = Foo()
    .onEvent(IRCEvent.Type.CHAN)
    .onEvent(IRCEvent.Type.EMOTE)
    .onEvent(IRCEvent.Type.QUERY)
    .chainable(true)
    .verbose(false);

assert(f.acceptedEventTypes == [ IRCEvent.Type.CHAN, IRCEvent.Type.EMOTE, IRCEvent.Type.QUERY ]);
assert(f.chainable);
assert(!f.verbose);

Meta