[dmd-beta] rvalue references
kenji hara
k.hara.pg at gmail.com
Tue Apr 10 18:23:44 PDT 2012
2012年4月11日9:57 Walter Bright <walter at digitalmars.com>:
> *** Allow rvalue references, however, disallow any implicit conversions of
> the literal's type in the process of taking a reference to it. ***
It sounds good. After the changing, following code may work.
struct S {
int val;
bool opEquals(const ref S rhs) const { return val == rhs.val; }
}
void main() {
S s1 = S(10);
assert(S == S(10));
// S(10) is rvalue but you can bind it with ref as *rvalue reference*.
}
> With all that, I intend to once again allow struct literals to be lvalues for 2.059.
But it sounds not good. We should keep all kind of literals (includinc
struct ones) as rvalue.
struct S {}
void f( S s) { printf("receives rvalue\n"); }
void f(ref S s) { printf("receives lvalue\n"); }
viod main() {
f(S());
// if you revert struct literal to lvalue, this call matches both
ovarloads of f,
// then causes ambiguous error.
}
> Somewhat later, also allow references to other literals like 0 and 5.6.
Agreed. Introducing *rvalue reference* requires such changes for consistency.
But, again, keep all literals rvalue, please.
Kenji Hara
More information about the dmd-beta
mailing list