www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1411] New: ref Tuple should transform to Tuple of ref's

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: hhasemann 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;
}


-- 
Aug 10 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1411


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
         OS/Version|Linux                       |All



https://github.com/D-Programming-Language/dmd/pull/202

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 03 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1411


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



15:59:09 PDT ---
https://github.com/D-Programming-Language/dmd/commit/aa270baa7eb856cc9ae4ae7701a8701eb8477fda

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 03 2011