zorael / kameloso

IRC bot with Twitch support
Boost Software License 1.0
9 stars 3 forks source link

Replace a lot of boilerplate with a `Wrap` template #116

Closed zorael closed 2 years ago

zorael commented 2 years ago

With our new IRCEventHandler UDA scheme, there was a lot of manual boilerplate involved in defining the various methods; .onEvent, .channelPolicy, .chainable and so forth. But they really only did two things; take the passed value and save it somewhere else, then return this by reference.

bool _chainable;

ref auto chainable(bool newValue)
{
    this._chainable = newValue;
    return this;
}

Now it's done with a mixin template Wrap that automatically generates them.

bool _chainable;

mixin Wrap!("chainable", _chainable);

Compilation memory went up some, but marginally.

IRCEventHandler.Regex.expression is an exception in that it not only saves the passed expression, but also instantiates the regex engine. So it was left as-was.