11/7/2012 9:04 PM, martin пишет:
On Wednesday, 7 November 2012 at 14:07:31 UTC, martin wrote:C++: void f(T& a) { // for lvalues this->resource = a.resource; a.resetResource(); } void f(T&& a) { // for rvalues (moved) this->resource = a.resource; a.resetResource(); }D: void f(ref T a) { // for lvalues this.resource = a.resource; a.resetResource(); } void f(T a) { // rvalue argument is not copied, but moved this.resource = a.resource; a.resetResource(); }You could probably get away with a single-line overload, both in C++ and D: C++: void f(T& a) { // for lvalues // convert a to mutable rvalue reference and // invoke the main overload f(T&&) f(std::move(a)); } D: void f(T a) { // rvalue argument is not copied, but moved // the original argument is now named a (an lvalue) // invoke the main overload f(ref T) f(a); }
Yup, and I'd like auto ref to actually do this r-value trampoline for me. -- Dmitry Olshansky
