From: Jason Hise (chaos_at_[hidden])
Date: 2005-04-28 09:12:39
Based on the recent discussions involving pointer container copyability,
I thought I might want to get some opinions about a similar design
decision made in singleton.
The singleton provides a smart pointer to access the instance, which
does locking, null state detection, and possibly recreation under the
covers when operator -> is used. As a result, it would be comparatively
unsafe to use a raw pointer or a straight reference to the singleton
instance, which can do none of these checks when being used to access a
member of the singleton. Because of this, I did not provide an
overloaded unary * operator for the singleton pointer class. However,
there might be times when the singleton needs to be used polymorphically
as some other base class or interface, and in such cases the only way to
manage this is with a raw pointer or reference. Thus I currently
provide a member function get_unsafe_ptr which actually returns a raw
pointer to the instance.
Should I provide an operator * to return an 'unsafe reference', or add a
function like get_unsafe_reference(), which forces the programmer to
consider carefully before calling it? Should I add neither, and only
leave get_unsafe_ptr? Are there cases in which the non-standard
spelling of 'get a reference from the pointer' could cause problems?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk