www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to define delegate what returns ref?

reply Oleg B <code.viator gmail.com> writes:
Hello all!

syntax

     ref int delegate() foo0;

or

     ref(int) delegate() foo1;

or

     int delegate() ref foo2;

are not valid.

if I try alias

     alias refint = ref int;
     refint delegate() foo3;

foo3 have type `int delegate()` (without `ref`)
and it can't store delegate from object method that have `int 
delegate() ref` (that can be printed if we use 
`typeof(&someobject.method).stringof`)

I found only one ugly way to do this

     interface Foo { ref int func(); }
     typeof(&Foo.init.func) foo4;

How to do this more clearly?
Aug 28 2020
parent reply kinke <noone nowhere.com> writes:
On Friday, 28 August 2020 at 11:46:15 UTC, Oleg B wrote:
 How to do this more clearly?
alias Dg = ref int delegate(); Dg foo;
Aug 28 2020
parent Oleg B <code.viator gmail.com> writes:
On Friday, 28 August 2020 at 11:50:35 UTC, kinke wrote:
 On Friday, 28 August 2020 at 11:46:15 UTC, Oleg B wrote:
 How to do this more clearly?
alias Dg = ref int delegate(); Dg foo;
Thanks!
Aug 28 2020