On 5/15/18 10:26 AM, Yuxuan Shui wrote:
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?)

It seems opDispatch isn't being used in the with statement. That seems like a bug, or maybe a limitation. I'm not sure how "with" works, but I assumed it would try calling as a member, and then if it doesn't work, try the call normally. Probably it's checking to see if it has that member first.

Annoying...

-Steve

Reply via email to