On Tuesday, 15 May 2018 at 13:59:37 UTC, jmh530 wrote:
On Tuesday, 15 May 2018 at 13:16:21 UTC, Steven Schveighoffer
wrote:
[snip]
Hm... neat idea. Somehow, opDispatch can probably be used to
make this work even more generically (untested):
struct WithAlloc(alias alloc)
{
auto opDispatch(string s, Args...)(auto ref Args args) if
(__traits(compiles, mixin(s ~ "(args, alloc)")))
{
mixin("return " ~ s ~ "(args, alloc);");
}
}
-Steve
Example:
https://run.dlang.io/is/RV2xIH
Sadly with(WithAlloc!alloc) doesn't work. (If you have to use
withAlloc.func everywhere, it kind of destroy the point, doesn't
it?)