www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Function pointer array slice?

reply "Tofu Ninja" <emmons0 purdue.edu> writes:
So simple syntax question, how do I make an array slice of 
function pointers?

I just have no idea where to put the [] on something like

      void function() nothrow pure  nogc  safe arrayName;

Or should I just alias it and make an array of the alias?

      alias f = void function() nothrow pure  nogc  safe;
      f[] arrayName;
Jul 11 2015
parent reply "tcak" <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote:
 So simple syntax question, how do I make an array slice of 
 function pointers?

 I just have no idea where to put the [] on something like

      void function() nothrow pure  nogc  safe arrayName;

 Or should I just alias it and make an array of the alias?

      alias f = void function() nothrow pure  nogc  safe;
      f[] arrayName;
Alias is the correct way IMO.
Jul 11 2015
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Sat, 11 Jul 2015 09:54:40 +0000, tcak wrote:

 On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote:
 So simple syntax question, how do I make an array slice of function
 pointers?

 I just have no idea where to put the [] on something like

      void function() nothrow pure  nogc  safe arrayName;

 Or should I just alias it and make an array of the alias?

      alias f =3D void function() nothrow pure  nogc  safe;
      f[] arrayName;
=20 Alias is the correct way IMO.
yet void function() nothrow pure nogc safe [2]arrayName; is perfectly fine too.=
Jul 11 2015
parent reply "Tofu Ninja" <emmons0 purdue.edu> writes:
On Saturday, 11 July 2015 at 10:54:45 UTC, ketmar wrote:
 On Sat, 11 Jul 2015 09:54:40 +0000, tcak wrote:

 On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote:
 So simple syntax question, how do I make an array slice of 
 function pointers?

 I just have no idea where to put the [] on something like

      void function() nothrow pure  nogc  safe arrayName;

 Or should I just alias it and make an array of the alias?

      alias f = void function() nothrow pure  nogc  safe;
      f[] arrayName;
Alias is the correct way IMO.
yet void function() nothrow pure nogc safe [2]arrayName; is perfectly fine too.
Ahh, guess that makes sense, I kept trying to put the [] over near function()... looks weird as hell though. I really wish you could put types in parens, I feel like things like this would make way more sense if you could write (void function() nothrow pure nogc safe)[] arrayName; Reading it, that makes wayyy more sense to me, to bad I can't write this...
Jul 11 2015
parent ketmar <ketmar ketmar.no-ip.org> writes:
On Sat, 11 Jul 2015 11:37:03 +0000, Tofu Ninja wrote:

   void function() nothrow pure  nogc  safe [2]arrayName;

 is perfectly fine too.
=20 Ahh, guess that makes sense, I kept trying to put the [] over near function()...
attributes are the parts of the type. and the rule is really simple: put=20 "[]" array declaration immediately left of the array name. ;-)
 looks weird as hell though. I really wish you could put
 types in parens, I feel like things like this would make way more sense
 if you could write
=20
       (void function() nothrow pure  nogc  safe)[] arrayName;
=20
 Reading it, that makes wayyy more sense to me, to bad I can't write
 this...
i agree, this is somewhat easier to read. but it requires grammar=20 changes, i believe, and dunno what consequences that may have. yet it may=20 worth filling a ER.=
Jul 11 2015