Passing refs with delegates
Mark J Twain via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 3 17:31:03 PDT 2016
On Wednesday, 3 August 2016 at 08:12:00 UTC, Ali Çehreli wrote:
> On 08/02/2016 07:55 PM, Mark J Twain wrote:
>>[...]
>
> I didn't know one could use 'auto ref' in this case but the
> following simple test works:
>
> auto foo(Func, Args...)(Func callback, auto ref Args args) {
> return callback(args);
> }
>
> double bar(ref int i, int j, ref int k) {
> i = 100;
> k = 102;
> return 7.5;
> }
>
> void main() {
> int i;
> int k;
> auto a = foo(&bar, i, 2, k);
> assert(i == 100);
> assert(k == 102);
> assert(a == 7.5);
> }
>
> Ali
Interesting, it might just do! Thanks.
More information about the Digitalmars-d-learn
mailing list