[Issue 5710] cannot use delegates as parameters to non-global template

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 6 11:01:09 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=5710


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #16 from Steven Schveighoffer <schveiguy at yahoo.com> 2013-05-06 11:01:01 PDT ---
(In reply to comment #0)

> class Foo {
>     uint doStuff(alias fun)(uint a, uint b) { return fun(a, b); }
> }
> 
> void main() {
>     auto foo = new Foo;
> 
>     uint add(uint a, uint b) { return a + b; }
> 
>     foo.doStuff!add(1, 2);
> }

This is definitely not good.

I don't think we need to alter the ABI for this.  The 'this' pointer of the
frame isn't used inside doStuff, just inside the template instantiation.  The
compiler can be smart enough to recognize that fun(a, b) is really:

fun(a, b, frameptr), and that frameptr is passed implicitly as a parameter.  It
does not have to be spelled out in the parameters to doStuff.

I don't like the *spirit* of kenji's solution, that context pointers are an
array.  Given that this is a template, and the compiler has the ability to pass
and receive, and write code for, any hidden parameter it wishes, it's simply a
matter of lowering.  Like foreach, which injects hidden code and function
return handling.

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


More information about the Digitalmars-d-bugs mailing list