struct Point { float x, y; } int a = 34; Point b = { 3, 4 }; int c = 32; enum d = 42; auto inner = Closure!(c, d)(); auto outer = Closure!(inner, a, b)(); static assert (inner.sizeof >= (void*).sizeof); static assert (outer.sizeof >= (void*).sizeof); assert (inner.c == 32); assert (outer.a == 34); assert (outer.b == Point(3, 4)); assert (outer.c == 32); outer.a++; assert (a == 35); assert (outer.a == 35); outer.c++; assert (c == 33); assert (inner.c == 33); assert (outer.c == 33); void someFunc(C)(C closure) { assert (closure.a == 35); with (closure) assert (a == 35); int local = 85; auto ctx = Closure!(closure, local)(); assert (ctx.local == 85); assert (ctx.a == 35); } someFunc(outer);