[Issue 1411] New: ref Tuple should transform to Tuple of ref's
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 10 12:29:51 PDT 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1411
Summary: ref Tuple should transform to Tuple of ref's
Product: D
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: hhasemann at web.de
The following code does not compile because the delegate in the (*) row
expands to
int delegate(ref (int, char[], real)) dg;
more useful would be:
int delegate(ref int, ref char[], ref real) dg;
this way you could define opApplys parameters by template parameters
which is useful for stuff like iterators in "template libraries".
The workaround I currently use is also provided her.
----------
Code that does not compile because of the problem described above
----------
template Tuple(T ...) { alias T Tuple; }
int delegate(ref Tuple!(int, char[], real)) dg; // (*)
int f(ref int a, ref char[] b, ref real c) { return 77; }
void main() {
dg = &f;
}
--------
My workaround
--------
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;
}
--
More information about the Digitalmars-d-bugs
mailing list