From Piotr Rak, "added bool conversion for ref_ptr, when no implicit conversion to T* is used."

This commit is contained in:
Robert Osfield 2008-11-25 16:24:50 +00:00
parent a7a7115581
commit e3d1c4ba04

View File

@ -71,6 +71,18 @@ class ref_ptr
friend bool operator != (const T* ptr, const ref_ptr& rp) { return (ptr!=rp._ptr); } friend bool operator != (const T* ptr, const ref_ptr& rp) { return (ptr!=rp._ptr); }
bool operator < (const ref_ptr& rp) const { return (_ptr<rp._ptr); } bool operator < (const ref_ptr& rp) const { return (_ptr<rp._ptr); }
// follows is an implmentation of the "safe bool idiom", details can be found at:
// http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool
// http://lists.boost.org/Archives/boost/2003/09/52856.php
private:
typedef T* ref_ptr::*unspecified_bool_type;
public:
// safe bool conversion
operator unspecified_bool_type() const { return valid()? &ref_ptr::_ptr : 0; }
#endif #endif
T& operator*() const { return *_ptr; } T& operator*() const { return *_ptr; }