
Rob Stewart wrote:
A & object(proxy);
This is clever and would probably work. However, I have two questions:
A) What benefits would a 'smart reference' provide that the smart pointer doesn't already?
Safe access to the controlled object that you don't get with get_unsafe_ptr().
But that's what the smart pointer itself already provides. In what circumstances would it be better for client code to work with a smart reference than with a smart pointer? The smart pointer provides access to singleton members via the -> operator. A smart reference would be unable to provide access to singleton members via the dot operator without first being cast, assigned, or copied into a reference. Why would client code prefer this: void Foo ( ) { MySingleton::reference r = *( MySingleton::pointer ( ) ); static_cast < MySingleton & > ( r ).DoSomething ( ); } to this? void Foo ( ) { MySingleton::pointer p; p->DoSomething ( ); } It seems to me that smart references would be too clumsy to work with, and this would encourage client code to store and use real references just to avoid all the casting. -Jason