[Issue 8845] Can't pass immediate or rvalue args to ref function parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 27 05:09:23 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=8845


Maxim Fomin <maxim at maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim at maxim-fomin.ru


--- Comment #16 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-11-27 05:09:21 PST ---
Addressing Manu problem in first post: you cannot do it directly, but can
workaround by 

void foo(T)(ref const T i) {}

ref lvalueOf(T)(T expression)
{
   return [expression][0];
}

struct S(T)
{
   T t;
   ref get() { return t; }
   //alias get this;
}

void main()
{
   //foo(0-0);
   foo((0-0).lvalueOf);
   foo(S!int(0-0).get);
}

Second one is ugly but does not consume heap memory as first one, but it also
requires that foo() does not save reference somewhere (operation is safe
because S!int(0-0) is allocated within main scope, so passing pointer is fine,
until it is saved).

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


More information about the Digitalmars-d-bugs mailing list