Pitfalls of delegates inside ranges

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Mon Sep 2 08:06:52 PDT 2013


On 02/09/13 17:02, Artur Skawina wrote:
> I'm not sure where the delegates are supposed to be defined, the above
> allows defining then externally. If that is not required and you only
> need to select them from a set of predefined internal ones, then you can
> use your original code with something like:
>
>      private void function() _jump;
>      private void jump() { void delegate() dg; dg.ptr=&this; dg.funcptr=_jump; dg(); }
>      this(size_t max)
>      {
>          _max = max;
>          _jump = (&jump10).funcptr;
>      }
>
> That way `jump10` (and any other such functions) can still use the implicit-
> 'this'.

This second solution may actually rescue my revision to RandomSample -- I'm 
going to try it out. :-)



More information about the Digitalmars-d-learn mailing list