Thread overview
Is this a bug? "ref" affects only first tuple element
Aug 10, 2007
Henning Hasemann
Aug 10, 2007
Henning Hasemann
Aug 10, 2007
Henning Hasemann
Aug 10, 2007
BCS
August 10, 2007
Code is roughly like this (these lines are untested but you should get
the picture):

void foo(ref Tuple!(int, real, char[])) {
 // ...
}

This seems to be equivalent to the following:

void foo(ref int, real, char[]) {
 // ...
}

Note that the ref is only "applied" to the int. I dont know if this behaviour is intended because combining ref with tuples is not documented.

If it is intended and not going to change in 1.x (or if that is going to take long), I would like to know if there is a way to get the desired effect (ie. all types prefixed with "ref") without having to write a CTFE-parser that does the job via string-manipulation.

Henning

-- 
GPG Public Key: http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851 Fingerprint: 344F 4072 F038 BB9E B35D  E6AB DDD6 D36D 4191 1851
August 10, 2007
Some corrections / additions:

This code is more near to what I actually do in case the problem only occurs with delegates (I didnt test it on "normal" functions yet):

alias Tuple!(int, char[], real) T;

void foo(int delegate( ref T ) dg) {
 // ...
}

and it becomes something like this:

void foo(int delegate(ref int, char[], real) dg) {
 // ...
}

I'm using gdc from svn (dmd-1.018 compatible).

Henning

-- 
GPG Public Key: http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851 Fingerprint: 344F 4072 F038 BB9E B35D  E6AB DDD6 D36D 4191 1851
August 10, 2007
FYI: I found a workaround. It goes like this:

import std.traits;

/**
 * Given the types T create a delegate with return type int and
 * parameter
 * types ref T.
 * Example:
 *
 * TupleDelegate!(int, char[], void*) dg;
 *
 * is equivalent to:
 *
 * int delegate(ref int, ref char[], ref void*) dg;
 */
template TupleDelegate(T ...) {
  alias MkDelegate!(int delegate(), T) TupleDelegate;
}

/**
 * Helper for TupleDelegate.
 * Parameters:
 * D: accumulated delegate
 * A, B: Types to append to D's parameter list
 */
template MkDelegate(D, A, B ...) {
  alias MkDelegate!(int delegate(ParameterTypeTuple!(D), ref A), B) MkDelegate;
}

/**
 * Ditto
 */
template MkDelegate(D, A) {
  alias int delegate(ParameterTypeTuple!(D), ref A) MkDelegate;
}

-- 
GPG Public Key: http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851 Fingerprint: 344F 4072 F038 BB9E B35D  E6AB DDD6 D36D 4191 1851
August 10, 2007
Reply to Henning,

> the problem only
> occurs with delegates (I didnt test it on "normal" functions yet):

that says bug to me. Wright up a bug report and see if it's marked invalid (I hope it's not because there are some cool things you can do with ref tuples).