Bug 1411 – ref Tuple should transform to Tuple of ref's

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-08-10T14:29:00Z
Last change time
2015-06-09T01:27:40Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
hhasemann
Blocks
3106

Comments

Comment #0 by hhasemann — 2007-08-10T14:29:50Z
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; }
Comment #1 by yebblies — 2011-07-03T03:25:53Z
Comment #2 by bugzilla — 2011-07-03T15:59:09Z