Consistent 'bool' conversions; scoped_ptr(auto_ptr); get_pointer(scoped_ptr) added.

[SVN r14496]
This commit is contained in:
Peter Dimov
2002-07-17 15:15:39 +00:00
parent af6fe18c9d
commit 547888d507
4 changed files with 80 additions and 15 deletions
+16
View File
@@ -33,6 +33,8 @@ private:
scoped_array(scoped_array const &);
scoped_array & operator=(scoped_array const &);
typedef scoped_array<T> this_type;
public:
typedef T element_type;
@@ -67,6 +69,20 @@ public:
return ptr;
}
// implicit conversion to "bool"
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::get;
}
bool operator! () const // never throws
{
return px == 0;
}
void swap(scoped_array & b) // never throws
{
T * tmp = b.ptr;