On Wednesday, 19 October 2016 at 17:42:39 UTC, Guillaume Piolat wrote:
On Tuesday, 18 October 2016 at 06:30:15 UTC, Namespace wrote:
On Tuesday, 18 October 2016 at 02:54:08 UTC, Manu wrote:
I just want to be able to pass an rvalue to a function that receives a const ref... that's why I came to this forum in the first place like,
7 years ago. 7 years later... still can't.

I recently wrote a PR for p0nce D idioms, which shows how you can do that
https://github.com/p0nce/d-idioms/pull/119

Just wanted to add that I still don't know (I'm lazy) what "auto ref" parameters, "auto ref" return, and friends do in D.
ref is somewhat easy to explain in C++ but complicated in D.

For each auto ref argument the compiler will lazily generate 2^N functions (therefore "template bloat" if you overdo it). Example:

----
struct A { int id; }
void test(T)(auto ref T a) { }

A a = A(42);
test(a);
----

will generate one function, which takes the argument by ref:
----
void test(ref A a) { }
----

Another call
----
test(A(42));
----

will generate another function, which takes the argument by value:
----
void test(A a) { }
----

That's more ore less the magic behind auto ref.

Reply via email to