From 235994873faff1e2c58d6adb5a56d6766a386e79 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 25 Sep 2005 21:49:08 +0000 Subject: [PATCH] Documented conversion to 'unspecified bool' [SVN r31111] --- scoped_array.htm | 30 ++++++++++++++++++------------ scoped_ptr.htm | 18 ++++++++++++------ shared_array.htm | 18 ++++++++++++------ 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/scoped_array.htm b/scoped_array.htm index 2e1081c..93b1cf9 100644 --- a/scoped_array.htm +++ b/scoped_array.htm @@ -5,8 +5,8 @@ -

boost.png (6897 bytes)scoped_array - class template

+

boost.png (6897 bytes)scoped_array class template

The scoped_array class template stores a pointer to a dynamically allocated array. (Dynamically allocated arrays are allocated with the C++ new[] expression.) The array pointed to is guaranteed to be deleted, either on @@ -14,10 +14,9 @@

The scoped_array template is a simple solution for simple needs. It supplies a basic "resource acquisition is initialization" facility, without shared-ownership or transfer-of-ownership semantics. Both its name and - enforcement of semantics (by being - noncopyable) signal its intent to retain ownership solely within the - current scope. Because it is - noncopyable, + enforcement of semantics (by being + noncopyable) signal its intent to retain ownership solely within the + current scope. Because it is noncopyable, it is safer than shared_array for pointers which should not be copied.

Because scoped_array is so simple, in its usual implementation every operation is as fast as a built-in array pointer and it has no more space @@ -48,6 +47,8 @@ T & operator[](std::ptrdiff_t i) const; // never throws T * get() const; // never throws + operator unspecified-bool-type() const; // never throws + void swap(scoped_array & b); // never throws }; @@ -90,6 +91,10 @@

T * get() const; // never throws

Returns the stored pointer. T need not be a complete type. See the smart pointer common requirements.

+

conversions

+
operator unspecified-bool-type () const; // never throws
+

Returns an unspecified value that, when used in boolean contexts, is equivalent + to get() != 0.

swap

void swap(scoped_array & b); // never throws

Exchanges the contents of the two smart pointers. T need not be a @@ -101,11 +106,12 @@

Equivalent to a.swap(b). Matches the interface of std::swap. Provided as an aid to generic programming.


-

Revised 09 January 2003

+

Revised + 09 January 2003

Copyright 1999 Greg Colvin and Beman Dawes. Copyright 2002 Darin Adler. - Permission to copy, use, modify, sell and distribute this document is granted - provided this copyright notice appears in all copies. This document is provided - "as is" without express or implied warranty, and with no claim as to its - suitability for any purpose.

+ Copyright 2002-2005 Peter Dimov. Permission to copy, use, modify, sell and + distribute this document is granted provided this copyright notice appears in + all copies. This document is provided "as is" without express or implied + warranty, and with no claim as to its suitability for any purpose.

- \ No newline at end of file + diff --git a/scoped_ptr.htm b/scoped_ptr.htm index f3a0155..1c6458d 100644 --- a/scoped_ptr.htm +++ b/scoped_ptr.htm @@ -5,8 +5,8 @@ -

boost.png (6897 bytes)scoped_ptr - class template

+

boost.png (6897 bytes)scoped_ptr class template

The scoped_ptr class template stores a pointer to a dynamically allocated object. (Dynamically allocated objects are allocated with the C++ new expression.) The object pointed to is guaranteed to be deleted, either on destruction of the scoped_ptr, @@ -48,6 +48,8 @@ T * operator->() const; // never throws T * get() const; // never throws + operator unspecified-bool-type() const; // never throws + void swap(scoped_ptr & b); // never throws }; @@ -90,6 +92,10 @@

T * get() const; // never throws

Returns the stored pointer. T need not be a complete type. See the smart pointer common requirements.

+

conversions

+
operator unspecified-bool-type () const; // never throws
+

Returns an unspecified value that, when used in boolean contexts, is equivalent + to get() != 0.

swap

void swap(scoped_ptr & b); // never throws

Exchanges the contents of the two smart pointers. T need not be a @@ -150,8 +156,8 @@ Buckle my shoe

One common usage of scoped_ptr is to implement a handle/body (also called pimpl) idiom which avoids exposing the body (implementation) in the header file.

-

The scoped_ptr_example_test.cpp sample - program includes a header file, scoped_ptr_example.hpp, +

The scoped_ptr_example_test.cpp + sample program includes a header file, scoped_ptr_example.hpp, which uses a scoped_ptr<> to an incomplete type to hide the implementation. The instantiation of member functions which require a complete type occurs in the scoped_ptr_example.cpp @@ -165,10 +171,10 @@ Buckle my shoe given context. Use std::auto_ptr where transfer of ownership is required. (supplied by Dave Abrahams)


-

Revised +

Revised 09 January 2003

Copyright 1999 Greg Colvin and Beman Dawes. Copyright 2002 Darin Adler. - Copyright 2002 Peter Dimov. Permission to copy, use, modify, sell and + Copyright 2002-2005 Peter Dimov. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.

diff --git a/shared_array.htm b/shared_array.htm index 337f131..7c61f53 100644 --- a/shared_array.htm +++ b/shared_array.htm @@ -5,8 +5,8 @@ -

boost.png (6897 bytes)shared_array - class template

+

boost.png (6897 bytes)shared_array class template

The shared_array class template stores a pointer to a dynamically allocated array. (Dynamically allocated array are allocated with the C++ new[] expression.) The object pointed to is guaranteed to be deleted when the last shared_array @@ -53,6 +53,8 @@ bool unique() const; // never throws long use_count() const; // never throws + operator unspecified-bool-type() const; // never throws + void swap(shared_array<T> & b); // never throws }; @@ -139,6 +141,10 @@ implementations of shared_array that do not use an explicit reference count, it might be removed from some future version. Thus it should be used for debugging purposes only, and not production code.

+

conversions

+
operator unspecified-bool-type () const; // never throws
+

Returns an unspecified value that, when used in boolean contexts, is equivalent + to get() != 0.

swap

void swap(shared_ptr & b); // never throws

Exchanges the contents of the two smart pointers. T need not be a @@ -172,9 +178,9 @@ template<class T> 09 January 2003

Copyright 1999 Greg Colvin and Beman Dawes. Copyright 2002 Darin Adler. - Permission to copy, use, modify, sell and distribute this document is granted - provided this copyright notice appears in all copies. This document is provided - "as is" without express or implied warranty, and with no claim as to its - suitability for any purpose.

+ Copyright 2002-2005 Peter Dimov. Permission to copy, use, modify, sell and + distribute this document is granted provided this copyright notice appears in + all copies. This document is provided "as is" without express or implied + warranty, and with no claim as to its suitability for any purpose.