a lambda with arguments has type void?

cy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 7 15:02:49 PDT 2016


This program errors out, when I try to pass lambdas that take 
arguments. How am I getting the syntax wrong here? Is there some 
reason you can't do this?

import std.stdio;

void foo(Callable)(Callable bar) {
   bar();
}

void foo2(Callable)(Callable bar, int baz) {
   bar(baz);
}

void main() {
   foo({
	  writeln("okay");
	});
   foo2((bar) {
	  writeln("got",bar);
	},42);
   foo2((bar) => writeln("yay",bar), 42);
}




More information about the Digitalmars-d-learn mailing list