Walter Karas
Posts: 12
Nickname: wkaras
Registered: Dec, 2003
|
|
Re: A Brief Introduction to Rvalue References
|
Posted: May 28, 2012 8:41 AM
|
|
> Walter Karas wrote: > > Consider this code: > > > > extern void foo(A &a); > > extern void foo(A &&a); > > > > void bar(void) > > { > > A a,*ap = new A; > > > > foo(*ap); > > delete ap; > > > > foo(a); > > } > > > > Would the compiler be required or allowed to use the > > second overload of foo() for either of the two calls to > > foo() in bar() ? > > No. 'a' and '*ap' are not rvalues, so in your example, > foo(A&&a) will never be called.
Could it be forced like this?
foo(static_cast<A &&>(*ap));
foo(static_cast<A &&>(a));
> > > > Separate question: was consideration given to > requiring > > functions that take a rvalue reference to be equivalent > to > > an explicit destructor call on the object? And, in a > > question related to that question, does/should the > > Standard require that this: > > > > ap->~A(); > > delete static_cast<void *>(ap); > > > > work? > > I guess N1377 section "Alternative move designs" might be > of help to you: > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n13 > 77.htm#Alternative%20move%20designs > > Happy programming! > > -- Niels
|
|