improving scope(finally/success)
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 3 07:33:01 PST 2015
On 12/3/15 10:24 AM, Chris Wright wrote:
> You can already do it with a slight change, and it's not so painful, at
> least in simple functions:
>
> int foo(bool b) {
> auto result = 2;
> scope(exit) writeln(result);
> if (b) {
> result = 1;
> }
> return result;
> }
>
auto ref logCall(alias f, Args...)(auto ref Args args) {
auto ref printResult(T)(auto ref T t)
{
writeln(t);
return t;
}
return printResult(f(args))
}
logCall!foo(true);
-Steve
More information about the Digitalmars-d
mailing list