Function template declaration mystery...

Robert M. Münch robert.muench at saphirion.com
Wed Feb 28 17:47:22 UTC 2018


Hi, I'm lost reading some code:

A a;

auto do(alias f, A)(auto ref A _a){
	alias fun = unaryFun!f;
	return ...
	...
}

How is this alias stuff working? I mean what's the type of f? Is it an 
anonymous function which then gets checked to be unary? How is it 
recognized in the code using the function template?


This function can be called with code like this:

a.do((myType) {...myCode...});
do(a, (myType) {...myCode...});

What's wondering me here is that the template function only has one 
paraemter (_a) but I somehow can get my myCode into it. But the code 
looks like a parameter to me. So why isn't it like:

auto do(alias f, A)(auto ref A _a, ??? myCode){...

I'm a bit confused.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list