Re: Function template declaration mystery...

2018-03-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-03-01 12:01:19 +, Steven Schveighoffer said: 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

Re: Function template declaration mystery...

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/28/18 3:36 PM, Robert M. Münch wrote: 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. It means that it simply becomes the alias you passed in. It

Re: Function template declaration mystery...

2018-02-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 28, 2018 at 09:36:33PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: [...] > 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. [...]

Re: Function template declaration mystery...

2018-02-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-02-28 18:25:37 +, 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,

Re: Function template declaration mystery...

2018-02-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-02-28 18:09:41 +, H. S. Teoh said: Basically, the `alias f` is a catch-all template parameter that can bind to basically anything that has a symbol. It's typically used to bind to functions, delegates, and lambdas. Aha... ok that makes it a bit more clear. So, if I have: auto

Re: Function template declaration mystery...

2018-02-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-02-28 18:01:50 +, TheFlyingFiddle said: Testing this with: auto foo(alias f, A)(auto ref A a) { return f(a); } I can call foo either like this: foo!(x => x + x)(1); or 1.foo!(x => x + x); but these will give errors foo(1, x => x + x); //Error 1.foo(x => x + x); // Error I

Re: Function template declaration mystery...

2018-02-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/28/18 12:47 PM, Robert M. Münch wrote: 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

Re: Function template declaration mystery...

2018-02-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 28, 2018 at 06:47:22PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > 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

Re: Function template declaration mystery...

2018-02-28 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 17:47:22 UTC, Robert M. Münch wrote: 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 template declaration mystery...

2018-02-28 Thread Robert M. Münch via Digitalmars-d-learn
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