On 4/23/13 3:07 AM, Namespace wrote:
On Tuesday, 23 April 2013 at 03:30:35 UTC, Walter Bright wrote:
Previous discussions:

http://forum.dlang.org/thread/4f84d6dd.5090...@digitalmars.com#post-4F84D6DD.5090405:40digitalmars.com


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

I still like the Idea of DIP 36 (http://wiki.dlang.org/DIP36) with scope
ref / in ref. On this link we have also collected several other
suggested syntaxes.
But maybe we should discuss first, if auto ref could work for
non-templates.
This would mean that
1. auto ref generate code bloat for non-templates (doubled the function
2^n times)
or
2. auto ref works like scope ref would do (create a temporary lvalue and
pass this to the function). But that would mean that auto ref work
differently for templates and non-templates (maybe a problem?). If we
choose this we should also discuss about the lifetime of the temporary:
----
foo(auto ref A a) { }

foo(A());
// should then converted to
{
A __temp = A();
foo(__temp); // after this, __temp is destroyed
}
----
or
3. the compiler choose if an argument should be passed by ref, by value
or should be moved.
For example:
----
A a = A(42);
foo(a); // by ref
foo(A(23)); // move
----

That's on the mark. We need to make auto ref work with non-templates as well as templates, safely. The implementation mechanics may be different. Lifetime of temporaries is an important detail. I discuss such in http://d.puremagic.com/issues/show_bug.cgi?id=9238 but I never had the time to finish it.

Andrei

Reply via email to