Function template declaration mystery...

Robert M. Münch robert.muench at saphirion.com
Wed Feb 28 20:36:33 UTC 2018


On 2018-02-28 18:25:37 +0000, Steven Schveighoffer said:

> unaryFun is a template that returns a callable item.

That far I made it too :-)

> It could be a struct with an opCall, it could be a function template, 
> it could be an alias to a real function, it could be a function 
> pointer, delegate, etc.

As long as it's a function, makes sense.

> It also supports string lambdas, which existed before our current 
> lambda syntax.
> 
> i.e. alias f = unaryFun!"a - 5";
> assert(f(10) == 5);

Yes, that's what the docs state. And I can imagin this. Bit this 
sentence is a bit hard to understand: "If fun is not a string, unaryFun 
aliases itself away to fun." Whatever this means.

> This question is a little harder to understand. Perhaps you have real 
> code that shows what you are confused about?

Ok, here it is: https://pastebin.com/tKACi488

See lines 81-84 for how I call it. And the problem I have is that 
doSubscribe returns "something" I'm not sure what I can do with. But if 
the scope ends, my subscription seems to be deleted and hence is not 
called when a message is coming in (see line: 118)

And the question is now, what do I have to do that subscriptions that 
are done anywhere in the code survive the scope where they have been 
created?

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



More information about the Digitalmars-d-learn mailing list