How to declare an alias to a function literal type

2016-01-12 Thread ParticlePeter via Digitalmars-d-learn
I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void function( int i ) { myCode; } How would I declare an alias for void function( int i ) such that the case above would work like this: // alias MF = void function( int i ); // not

Re: How to declare an alias to a function literal type

2016-01-12 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 15:41:02 UTC, ParticlePeter wrote: I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void function( int i ) { myCode; } How would I declare an alias for void function( int i ) such that the case above would

Re: How to declare an alias to a function literal type

2016-01-12 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 12 Jan 2016 15:41:02 + ParticlePeter via Digitalmars-d-learn napsáno: > I have a function type and variable and assign a function to it: > > void function( int i ) myFunc; > myFunc = void function( int i ) { myCode; } > > How would I declare an

Re: How to declare an alias to a function literal type

2016-01-12 Thread anonymous via Digitalmars-d-learn
On 12.01.2016 16:41, ParticlePeter wrote: // alias MF = void function( int i ); // not working // alias void function( int i ) MF; // not working These are both fine. The first one is the preferred style. MF myFunc; myFunc = MF { myCode }; This line doesn't work. Function literals don't

Re: How to declare an alias to a function literal type

2016-01-12 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 16:22:48 UTC, ParticlePeter wrote: Actually, I do use only one param, and not int as well, hence I would like the parameter list to be part of the alias. Your example works though. This was confusing, lets start fresh: I have a function "otherFunc" which takes

Re: How to declare an alias to a function literal type

2016-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 01/12/2016 08:55 AM, ParticlePeter wrote: > I have a function "otherFunc" which takes a function with lots of > parameters as argument: > > void otherFunc( void function( ref int p1, float p2, ubyte p3, ... ) mf ); Ok. > otherFunc( void function( ref int p1, float p2, ubyte p3 ) { myCode;

Re: How to declare an alias to a function literal type

2016-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 01/12/2016 08:22 AM, ParticlePeter wrote: > On Tuesday, 12 January 2016 at 15:57:03 UTC, Marc Schütz wrote: > Not what I wanted, I wanted the parameter to be part of the alias: > myFunc = MF { ... } > > I want to pass such a function to another function: > > alias MF = void function(int i); >

Re: How to declare an alias to a function literal type

2016-01-12 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 16:00:37 UTC, Daniel Kozak wrote: V Tue, 12 Jan 2016 15:41:02 + ParticlePeter via Digitalmars-d-learn napsáno: I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void

Re: How to declare an alias to a function literal type

2016-01-12 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 15:57:03 UTC, Marc Schütz wrote: On Tuesday, 12 January 2016 at 15:41:02 UTC, ParticlePeter wrote: I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void function( int i ) { myCode; } How would I declare an

Re: How to declare an alias to a function literal type

2016-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 01/12/2016 07:41 AM, ParticlePeter wrote: > Please, if possible, also show me where I should have found the answer > (D Reference, Alis book It is not used with a function literal but searching for 'alias' below yields something close: :) http://ddili.org/ders/d.en/lambda.html

Re: How to declare an alias to a function literal type

2016-01-12 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 16:55:48 UTC, ParticlePeter wrote: I can rewrite the definition of otherFunc like this: void otherFunc( MF mf ); But I cannot pass an anonymous function to otherFunc like this: otherFunc( MF { myCode; } ); Thats what I want. Any working example? If I understand

Re: How to declare an alias to a function literal type

2016-01-12 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 17:03:49 UTC, Ali Çehreli wrote: On 01/12/2016 08:55 AM, ParticlePeter wrote: > I have a function "otherFunc" which takes a function with lots of > parameters as argument: > > void otherFunc( void function( ref int p1, float p2, ubyte p3, ... ) mf ); Ok. >

Re: How to declare an alias to a function literal type

2016-01-12 Thread anonymous via Digitalmars-d-learn
On 12.01.2016 17:55, ParticlePeter wrote: When I pass a parameter to otherFunc I use this syntax for an anonymous function parameter: otherFunc( void function( ref int p1, float p2, ubyte p3 ) { myCode; } ); You don't. That's not valid code. You can be using this: otherFunc( function void (

Re: How to declare an alias to a function literal type

2016-01-12 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 17:28:35 UTC, Marc Schütz wrote: On Tuesday, 12 January 2016 at 16:55:48 UTC, ParticlePeter wrote: [...] If I understand you correctly (not sure), you would like to write `MF` so that you don't need to specify the parameters in the lambda? That's not possible,