On Friday, 11 May 2018 at 18:55:03 UTC, Meta wrote:
On Friday, 11 May 2018 at 15:03:41 UTC, Uknown wrote:
[...]

It's not as pretty, and I don't know if it works outside this toy example yet, but you can do:

import std.stdio;

struct Allocator
{
    auto call(alias F, Args...)(Args args)
    {
        return F(this, args);
    }

    void deallocateAll()
    {
        writeln("deallocateAll");
    }
}

void f1(Allocator a, int n) { writeln("f1"); }
void f2(Allocator, string s, double d) { writeln("f2"); }

void main()
{
    with (Allocator())
    {
        scope(exit) deallocateAll;
        call!f1(2);
        call!f2("asdf", 1.0);
    }
}

I found another alternative to this:

https://godbolt.org/g/3Etims

Reply via email to