From 57c0ad44f399cf3d6e60c0d682a5408ba9600c45 Mon Sep 17 00:00:00 2001
From: Peter Dimov Synopsis
namespace boost {
- template<typename T> class scoped_array : noncopyable {
+ template<class T> class scoped_array : noncopyable {
public:
typedef T element_type;
@@ -50,7 +50,7 @@
void swap(scoped_array & b); // never throws
};
- template<typename T> void swap(scoped_array<T> & a, scoped_array<T> & b); // never throws
+ template<class T> void swap(scoped_array<T> & a, scoped_array<T> & b); // never throws
}
Members
@@ -96,7 +96,7 @@
requirements.
template<typename T> void swap(scoped_array<T> & a, scoped_array<T> & b); // never throws+
template<class T> void swap(scoped_array<T> & a, scoped_array<T> & b); // never throws
Equivalent to a.swap(b). Matches the interface of std::swap. Provided as an aid to generic programming.
namespace boost { - template<typename T> class scoped_ptr : noncopyable { + template<class T> class scoped_ptr : noncopyable { public: typedef T element_type; @@ -51,7 +51,7 @@ void swap(scoped_ptr & b); // never throws }; - template<typename T> void swap(scoped_ptr<T> & a, scoped_ptr<T> & b); // never throws + template<class T> void swap(scoped_ptr<T> & a, scoped_ptr<T> & b); // never throws }
template<typename T> void swap(scoped_ptr<T> & a, scoped_ptr<T> & b); // never throws+
template<class T> void swap(scoped_ptr<T> & a, scoped_ptr<T> & b); // never throws
Equivalent to a.swap(b). Matches the interface of std::swap. Provided as an aid to generic programming.
namespace boost { - template<typename T> class shared_array { + template<class T> class shared_array { public: typedef T element_type; explicit shared_array(T * p = 0); - template<typename D> shared_array(T * p, D d); + template<class D> shared_array(T * p, D d); ~shared_array(); // never throws shared_array(shared_array const & r); // never throws @@ -45,7 +45,7 @@ shared_array & operator=(shared_array const & r); // never throws void reset(T * p = 0); - template<typename D> void reset(T * p, D d); + template<class D> void reset(T * p, D d); T & operator[](std::ptrdiff_t i) const() const; // never throws T * get() const; // never throws @@ -56,14 +56,14 @@ void swap(shared_array<T> & b); // never throws }; - template<typename T> + template<class T> bool operator==(shared_array<T> const & a, shared_array<T> const & b); // never throws - template<typename T> + template<class T> bool operator!=(shared_array<T> const & a, shared_array<T> const & b); // never throws - template<typename T> + template<class T> bool operator<(shared_array<T> const & a, shared_array<T> const & b); // never throws - template<typename T> void swap(shared_array<T> & a, shared_array<T> & b); // never throws + template<class T> void swap(shared_array<T> & a, shared_array<T> & b); // never throws }
template<typename D> shared_array(T * p, D d);+
template<class D> shared_array(T * p, D d);
Constructs a shared_array, storing a copy of p and of d. Afterwards, the use count is 1. D's copy constructor and destructor must not throw. When the the time comes to delete @@ -109,7 +109,7 @@ then replaces this shared_array with the new one, destroying the replaced object. The only exception which may be thrown is std::bad_alloc. If an exception is thrown, delete[] p is called.
-template<typename D> void reset(T * p, D d);+
template<class D> void reset(T * p, D d);
Constructs a new shared_array as described above, then replaces this shared_array with the new one, destroying the replaced object. D's copy constructor must not throw. The only exception @@ -146,11 +146,11 @@ requirements.
template<typename T> +template<class T> bool operator==(shared_array<T> const & a, shared_array<T> const & b); // never throws -template<typename T> +template<class T> bool operator!=(shared_array<T> const & a, shared_array<T> const & b); // never throws -template<typename T> +template<class T> bool operator<(shared_array<T> const & a, shared_array<T> const & b); // never throwsCompares the stored pointers of the two smart pointers. T need not be a complete type. See the smart pointer common @@ -163,7 +163,7 @@ template<typename T> paragraph 2) but std::less<> on pointers is well-defined (20.3.3 [lib.comparisons] paragraph 8).
swap
-template<typename T> +@@ -188,7 +188,7 @@ void bad() literal zero, for consistency with built-in pointers. It is not clear yet whether this constructor should be left implicit, enabling 0 to be used as a shorthand for shared_ptr<T>().] -template<class T> void swap(shared_array<T> & a, shared_array<T> & b) // never throwsEquivalent to a.swap(b). Matches the interface of std::swap. Provided as an aid to generic programming.
diff --git a/shared_ptr.htm b/shared_ptr.htm index 87a29b0..f1ca5b2 100644 --- a/shared_ptr.htm +++ b/shared_ptr.htm @@ -88,31 +88,31 @@ void bad() class use_count_is_zero: public std::exception; - template<typename T> class weak_ptr; + template<class T> class weak_ptr; - template<typename T> class shared_ptr { + template<class T> class shared_ptr { public: typedef T element_type; shared_ptr(); - template<typename Y> explicit shared_ptr(Y * p); - template<typename Y, typename D> shared_ptr(Y * p, D d); + template<class Y> explicit shared_ptr(Y * p); + template<class Y, class D> shared_ptr(Y * p, D d); ~shared_ptr(); // never throws shared_ptr(shared_ptr const & r); // never throws - template<typename Y> shared_ptr(shared_ptr<Y> const & r); // never throws - template<typename Y> explicit shared_ptr(weak_ptr<Y> const & r); - template<typename Y> explicit shared_ptr(std::auto_ptr<Y> & r); + template<class Y> shared_ptr(shared_ptr<Y> const & r); // never throws + template<class Y> explicit shared_ptr(weak_ptr<Y> const & r); + template<class Y> explicit shared_ptr(std::auto_ptr<Y> & r); shared_ptr & operator=(shared_ptr const & r); // never throws - template<typename Y> shared_ptr & operator=(shared_ptr<Y> const & r); // never throws - template<typename Y> shared_ptr & operator=(std::auto_ptr<Y> & r); + template<class Y> shared_ptr & operator=(shared_ptr<Y> const & r); // never throws + template<class Y> shared_ptr & operator=(std::auto_ptr<Y> & r); void reset(); - template<typename Y> void reset(Y * p); - template<typename Y, typename D> void reset(Y * p, D d); + template<class Y> void reset(Y * p); + template<class Y, class D> void reset(Y * p, D d); T & operator*() const; // never throws T * operator->() const; // never throws @@ -126,24 +126,24 @@ void bad() void swap(shared_ptr & b); // never throws }; - template<typename T, typename U> + template<class T, class U> bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws - template<typename T, typename U> + template<class T, class U> bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws - template<typename T> + template<class T> bool operator<(shared_ptr<T> const & a, shared_ptr<T> const & b); // never throws - template<typename T> void swap(shared_ptr<T> & a, shared_ptr<T> & b); // never throws + template<class T> void swap(shared_ptr<T> & a, shared_ptr<T> & b); // never throws - template<typename T> T * get_pointer(shared_ptr<T> const & p); // never throws + template<class T> T * get_pointer(shared_ptr<T> const & p); // never throws - template<typename T, typename U> + template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r); // never throws - template<typename T, typename U> + template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r); - template<typename T, typename U> + template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r); - template<typename T, typename U> + template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r); // never throws }template<typename Y> explicit shared_ptr(Y * p);+template<class Y> explicit shared_ptr(Y * p);Requirements: p must be convertible to T *. Y must be a complete type. The expression
-delete p
must be @@ -230,7 +230,7 @@ void bad() specification should allow both; nevertheless, the ability to make a shared_ptr from this is considered essential by experienced smart pointer users.]template<typename Y, typename D> shared_ptr(Y * p, D d);+template<class Y, class D> shared_ptr(Y * p, D d);Requirements: p must be convertible to T *. D must be CopyConstructible. The copy constructor and destructor @@ -265,7 +265,7 @@ void bad() all.)
The requrement will be removed when the aforementioned issues are resolved.]
shared_ptr(shared_ptr const & r); // never throws -template<typename Y> shared_ptr(shared_ptr<Y> const & r); // never throws+template<class Y> shared_ptr(shared_ptr<Y> const & r); // never throws
Effects: Constructs a shared_ptr, as if by storing a copy of the pointer stored in r.
@@ -275,7 +275,7 @@ template<typename Y> shared_ptr(shared_ptr<Y> const & r); // nev
[The postcondition will be relaxed when a default-constructed shared_ptr is being copied.]
-template<typename Y> explicit shared_ptr(weak_ptr<Y> const & r);+
template<class Y> explicit shared_ptr(weak_ptr<Y> const & r);
Effects: Constructs a shared_ptr, as if by storing a copy of the pointer stored in r.
@@ -296,7 +296,7 @@ template<typename Y> shared_ptr(shared_ptr<Y> const & r); // nev interface is non-trivial.My opinion is that the added functionality is worth the cost. weak_ptr is provided in the reference implementation as a proof of concept.]
-template<typename Y> shared_ptr(std::auto_ptr<Y> & r);+template<class Y> shared_ptr(std::auto_ptr<Y> & r);Effects: Constructs a shared_ptr, as if by storing a copy of r.release().
Postconditions: use count is 1.
@@ -318,8 +318,8 @@ template<typename Y> shared_ptr(shared_ptr<Y> const & r); // nevassignment
shared_ptr & operator=(shared_ptr const & r); // never throws -template<typename Y> shared_ptr & operator=(shared_ptr<Y> const & r); // never throws -template<typename Y> shared_ptr & operator=(std::auto_ptr<Y> & r);+template<class Y> shared_ptr & operator=(shared_ptr<Y> const & r); // never throws +template<class Y> shared_ptr & operator=(std::auto_ptr<Y> & r);Effects: Equivalent to
shared_ptr(r).swap(*this)
.Notes: The use count updates caused by the temporary object construction @@ -347,11 +347,11 @@ q = p;
[reset() will offer the nothrow guarantee in a future implementation.]
-template<typename Y> void reset(Y * p);+template<class Y> void reset(Y * p);-Effects: Equivalent to
shared_ptr(p).swap(*this)
.template<typename Y, typename D> void reset(Y * p, D d);+template<class Y, class D> void reset(Y * p, D d);@@ -416,19 +416,19 @@ q = p;Effects: Equivalent to
shared_ptr(p, d).swap(*this)
.
template<typename T, typename U> +template<class T, class U> bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws-Returns:
a.get() == b.get()
.Throws: nothing.
template<typename T, typename U> +template<class T, class U> bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws-Returns:
a.get() != b.get()
.Throws: nothing.
template<typename T> +template<class T> bool operator<(shared_ptr<T> const & a, shared_ptr<T> const & b); // never throwsReturns: an unspecified value such that operator< is a strict @@ -447,7 +447,7 @@ q = p; subobjects' operator<.
The rest of the comparison operators are omitted by design.]
swap
-template<typename T> +template<class T> void swap(shared_ptr<T> & a, shared_ptr<T> & b); // never throwsEffects: Equivalent to
@@ -459,7 +459,7 @@ q = p; as this is currently the only legal way to supply a swap function that has a chance to be used by the standard library.]a.swap(b)
.get_pointer
-template<typename T> +template<class T> T * get_pointer(shared_ptr<T> const & p); // never throwsReturns:
@@ -468,7 +468,7 @@ q = p; mem_fn.p.get()
.shared_static_cast
-template<typename T, typename U> +template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r); // never throwsRequires: The expression
static_cast<T*>(r.get())
@@ -482,7 +482,7 @@ q = p; object twice.shared_dynamic_cast
-template<typename T, typename U> +template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r);Requires: The expression
dynamic_cast<T*>(r.get())
@@ -503,7 +503,7 @@ q = p; object twice.shared_polymorphic_cast
-template<typename T, typename U> +template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r);Requires: The expression
@@ -517,7 +517,7 @@ q = p;
Exception safety: If an exception is thrown, the function has no effect.
shared_polymorphic_downcast
-template<typename T, typename U> +template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r); // never throws-Requires: The expression
diff --git a/smart_ptr_test.cpp b/smart_ptr_test.cpp index eead369..0d02f8b 100644 --- a/smart_ptr_test.cpp +++ b/smart_ptr_test.cpp @@ -42,7 +42,7 @@ using boost::scoped_array; using boost::shared_ptr; using boost::shared_array; -template
+template void ck( const T* v1, T v2 ) { BOOST_TEST( *v1 == v2 ); } namespace { diff --git a/weak_ptr.htm b/weak_ptr.htm index 92bc284..d0273b4 100644 --- a/weak_ptr.htm +++ b/weak_ptr.htm @@ -61,21 +61,21 @@ if(shared_ptr<int> r = make_shared(q)) Synopsis
namespace boost { - template<typename T> class weak_ptr { + template<class T> class weak_ptr { public: typedef T element_type; weak_ptr(); - template<typename Y> weak_ptr(shared_ptr<Y> const & r); // never throws + template<class Y> weak_ptr(shared_ptr<Y> const & r); // never throws ~weak_ptr(); // never throws weak_ptr(weak_ptr const & r); // never throws - template<typename Y> weak_ptr(weak_ptr<Y> const & r); // never throws + template<class Y> weak_ptr(weak_ptr<Y> const & r); // never throws weak_ptr & operator=(weak_ptr const & r); // never throws - template<typename Y> weak_ptr & operator=(weak_ptr<Y> const & r); // never throws - template<typename Y> weak_ptr & operator=(shared_ptr<Y> const & r); // never throws + template<class Y> weak_ptr & operator=(weak_ptr<Y> const & r); // never throws + template<class Y> weak_ptr & operator=(shared_ptr<Y> const & r); // never throws void reset(); T * get() const; // never throws; deprecated, will disappear @@ -86,16 +86,16 @@ if(shared_ptr<int> r = make_shared(q)) void swap(weak_ptr<T> & b); // never throws }; - template<typename T, typename U> + template<class T, class U> bool operator==(weak_ptr<T> const & a, weak_ptr<U> const & b); // never throws - template<typename T, typename U> + template<class T, class U> bool operator!=(weak_ptr<T> const & a, weak_ptr<U> const & b); // never throws - template<typename T> + template<class T> bool operator<(weak_ptr<T> const & a, weak_ptr<T> const & b); // never throws - template<typename T> void swap(weak_ptr<T> & a, weak_ptr<T> & b); // never throws + template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b); // never throws - template<typename T> + template<class T> shared_ptr<T> make_shared(weak_ptr<T> const & r); // never throws } @@ -118,7 +118,7 @@ if(shared_ptr<int> r = make_shared(q))Notes: T need not be a complete type. See the smart pointer common requirements.
template<typename Y> weak_ptr(shared_ptr<Y> const & r); // never throws+template<class Y> weak_ptr(shared_ptr<Y> const & r); // never throwsEffects: Constructs a weak_ptr, as if by storing a copy of the pointer stored in r.
@@ -128,7 +128,7 @@ if(shared_ptr<int> r = make_shared(q)) stored pointer become 0.weak_ptr(weak_ptr const & r); // never throws -template<typename Y> weak_ptr(weak_ptr<Y> const & r); // never throws+template<class Y> weak_ptr(weak_ptr<Y> const & r); // never throwsEffects: Constructs a weak_ptr, as if by storing a copy of the pointer stored in r.
@@ -147,8 +147,8 @@ template<typename Y> weak_ptr(weak_ptr<Y> const & r); // never tassignment
weak_ptr & operator=(weak_ptr const & r); // never throws -template<typename Y> weak_ptr & operator=(weak_ptr<Y> const & r); // never throws -template<typename Y> weak_ptr & operator=(shared_ptr<Y> const & r); // never throws+template<class Y> weak_ptr & operator=(weak_ptr<Y> const & r); // never throws +template<class Y> weak_ptr & operator=(shared_ptr<Y> const & r); // never throwsEffects: Equivalent to
weak_ptr(r).swap(*this)
.Throws: nothing.
@@ -205,9 +205,9 @@ template<typename Y> weak_ptr & operator=(shFree Functions
comparison
-template<typename T, typename U> +template<class T, class U> bool operator==(weak_ptr<T> const & a, weak_ptr<U> const & b); // never throws -template<typename T, typename U> +template<class T, class U> bool operator!=(weak_ptr<T> const & a, weak_ptr<U> const & b); // never throws-Returns:
@@ -215,7 +215,7 @@ template<typename T, typename U>a.get() == b.get()
.Notes: T need not be a complete type. See the smart pointer common requirements.
template<typename T> +template<class T> bool operator<(weak_ptr<T> const & a, weak_ptr<T> const & b); // never throwsReturns: an implementation-defined value such that operator< is @@ -227,7 +227,7 @@ template<typename T, typename U> pointer common requirements.
swap
-template<typename T> +template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b) // never throwsEffects: Equivalent to
@@ -236,7 +236,7 @@ template<typename T, typename U> generic programming.a.swap(b)
.make_shared
-template<typename T> +template<class T> shared_ptr<T> make_shared(weak_ptr<T> & const r) // never throwsReturns:
r.expired()? shared_ptr<T>(): shared_ptr<T>(r)
.