diff --git a/doc/smart_ptr.adoc b/doc/smart_ptr.adoc index 361b528..5b452c7 100644 --- a/doc/smart_ptr.adoc +++ b/doc/smart_ptr.adoc @@ -13,7 +13,6 @@ Greg Colvin, Beman Dawes, Peter Dimov, Glen Fernandes :toclevels: 2 :idprefix: :listing-caption: Code Example -:table-caption: Illustration :docinfo: private-footer :leveloffset: +1 diff --git a/doc/smart_ptr/enable_shared_from_this.adoc b/doc/smart_ptr/enable_shared_from_this.adoc index 77037d3..26dc9fb 100644 --- a/doc/smart_ptr/enable_shared_from_this.adoc +++ b/doc/smart_ptr/enable_shared_from_this.adoc @@ -55,17 +55,15 @@ int main() `enable_shared_from_this` is defined in ``. ``` -namespace boost -{ +namespace boost { -template class enable_shared_from_this -{ -private: + template class enable_shared_from_this { + private: // exposition only weak_ptr weak_this_; -protected: + protected: enable_shared_from_this() = default; ~enable_shared_from_this() = default; @@ -73,16 +71,15 @@ protected: enable_shared_from_this(const enable_shared_from_this&) noexcept; enable_shared_from_this& operator=(const enable_shared_from_this&) noexcept; -public: + public: shared_ptr shared_from_this(); shared_ptr shared_from_this() const; weak_ptr weak_from_this() noexcept; weak_ptr weak_from_this() const noexcept; + } } - -} // namespace boost ``` ## Members diff --git a/doc/smart_ptr/intrusive_ptr.adoc b/doc/smart_ptr/intrusive_ptr.adoc index 392f1c3..1c729cd 100644 --- a/doc/smart_ptr/intrusive_ptr.adoc +++ b/doc/smart_ptr/intrusive_ptr.adoc @@ -41,12 +41,10 @@ As a general rule, if it isn't obvious whether `intrusive_ptr` better fits your `intrusive_ptr` is defined in ``. ``` -namespace boost -{ +namespace boost { -template class intrusive_ptr -{ -public: + template class intrusive_ptr { + public: typedef T element_type; @@ -71,50 +69,49 @@ public: T * get() const noexcept; T * detach() noexcept; - operator unspecified-bool-type() const noexcept; + explicit operator bool () const noexcept; void swap(intrusive_ptr & b) noexept; -}; + }; -template -bool operator==(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; + template + bool operator==(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; -template -bool operator!=(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; + template + bool operator!=(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; -template -bool operator==(intrusive_ptr const & a, U * b) noexcept; + template + bool operator==(intrusive_ptr const & a, U * b) noexcept; -template -bool operator!=(intrusive_ptr const & a, U * b) noexcept; + template + bool operator!=(intrusive_ptr const & a, U * b) noexcept; -template -bool operator==(T * a, intrusive_ptr const & b) noexcept; + template + bool operator==(T * a, intrusive_ptr const & b) noexcept; -template -bool operator!=(T * a, intrusive_ptr const & b) noexcept; + template + bool operator!=(T * a, intrusive_ptr const & b) noexcept; -template -bool operator<(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; + template + bool operator<(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; -template void swap(intrusive_ptr & a, intrusive_ptr & b) noexcept; + template void swap(intrusive_ptr & a, intrusive_ptr & b) noexcept; -template T * get_pointer(intrusive_ptr const & p) noexcept; + template T * get_pointer(intrusive_ptr const & p) noexcept; -template -intrusive_ptr static_pointer_cast(intrusive_ptr const & r) noexcept; + template + intrusive_ptr static_pointer_cast(intrusive_ptr const & r) noexcept; -template -intrusive_ptr const_pointer_cast(intrusive_ptr const & r) noexcept; + template + intrusive_ptr const_pointer_cast(intrusive_ptr const & r) noexcept; -template -intrusive_ptr dynamic_pointer_cast(intrusive_ptr const & r) noexcept; + template + intrusive_ptr dynamic_pointer_cast(intrusive_ptr const & r) noexcept; -template -std::basic_ostream & operator<< (std::basic_ostream & os, - intrusive_ptr const & p); - -} // namespace boost + template + std::basic_ostream & operator<< (std::basic_ostream & os, + intrusive_ptr const & p); +} ``` ## Members @@ -275,17 +272,18 @@ the implications are thoroughly understood. ### conversions ``` -operator unspecified-bool-type () const noexcept; +explicit operator bool () const noexcept; ``` [none] * {blank} + -Returns:: an unspecified value that, when used in boolean contexts, is equivalent to `get() != 0`. +Returns:: `get() != 0`. NOTE: This conversion operator allows `intrusive_ptr` objects to be used in boolean contexts, -like `if (p && p\->valid()) {}`. The actual target type is typically a pointer to a member function, -avoiding many of the implicit conversion pitfalls. +like `if (p && p\->valid()) {}`. + +NOTE: On C++03 compilers, the return value is of an unspecified type. ### swap @@ -304,7 +302,7 @@ Effects:: Exchanges the contents of the two smart pointers. ``` template -bool operator==(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; + bool operator==(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; ``` [none] @@ -314,7 +312,7 @@ Returns:: `a.get() == b.get()`. ``` template -bool operator!=(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; + bool operator!=(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; ``` [none] @@ -324,7 +322,7 @@ Returns:: `a.get() != b.get()`. ``` template -bool operator==(intrusive_ptr const & a, U * b) noexcept; + bool operator==(intrusive_ptr const & a, U * b) noexcept; ``` [none] @@ -334,7 +332,7 @@ Returns:: `a.get() == b`. ``` template -bool operator!=(intrusive_ptr const & a, U * b) noexcept; + bool operator!=(intrusive_ptr const & a, U * b) noexcept; ``` [none] @@ -344,7 +342,7 @@ Returns:: `a.get() != b`. ``` template -bool operator==(T * a, intrusive_ptr const & b) noexcept; + bool operator==(T * a, intrusive_ptr const & b) noexcept; ``` [none] @@ -354,7 +352,7 @@ Returns:: `a == b.get()`. ``` template -bool operator!=(T * a, intrusive_ptr const & b) noexcept; + bool operator!=(T * a, intrusive_ptr const & b) noexcept; ``` [none] @@ -364,7 +362,7 @@ Returns:: `a != b.get()`. ``` template -bool operator<(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; + bool operator<(intrusive_ptr const & a, intrusive_ptr const & b) noexcept; ``` [none] @@ -402,7 +400,7 @@ NOTE: Provided as an aid to generic programming. Used by `mem_fn`. ``` template -intrusive_ptr static_pointer_cast(intrusive_ptr const & r) noexcept; + intrusive_ptr static_pointer_cast(intrusive_ptr const & r) noexcept; ``` [none] @@ -414,7 +412,7 @@ Returns:: `intrusive_ptr(static_cast(r.get()))`. ``` template -intrusive_ptr const_pointer_cast(intrusive_ptr const & r) noexcept; + intrusive_ptr const_pointer_cast(intrusive_ptr const & r) noexcept; ``` [none] @@ -426,7 +424,7 @@ Returns:: `intrusive_ptr(const_cast(r.get()))`. ``` template -intrusive_ptr dynamic_pointer_cast(intrusive_ptr const & r) noexcept; + intrusive_ptr dynamic_pointer_cast(intrusive_ptr const & r) noexcept; ``` [none] @@ -438,7 +436,7 @@ Returns:: `intrusive_ptr(dynamic_cast(r.get()))`. ``` template -std::basic_ostream & operator<< (std::basic_ostream & os, + std::basic_ostream & operator<< (std::basic_ostream & os, intrusive_ptr const & p); ``` diff --git a/doc/smart_ptr/pointer_to_other.adoc b/doc/smart_ptr/pointer_to_other.adoc index d8c5a52..d903cad 100644 --- a/doc/smart_ptr/pointer_to_other.adoc +++ b/doc/smart_ptr/pointer_to_other.adoc @@ -44,39 +44,37 @@ template class FloatPointerHolder `pointer_to_other` is defined in ``. ``` -namespace boost -{ +namespace boost { -template struct pointer_to_other; + template struct pointer_to_other; -template class Sp> - struct pointer_to_other< Sp, U > -{ - typedef Sp type; -}; + template class Sp> + struct pointer_to_other< Sp, U > + { + typedef Sp type; + }; -template class Sp> - struct pointer_to_other< Sp, U > -{ + template class Sp> + struct pointer_to_other< Sp, U > + { typedef Sp type; -}; + }; -template class Sp> - struct pointer_to_other< Sp, U > -{ + template class Sp> + struct pointer_to_other< Sp, U > + { typedef Sp type; -}; + }; -template - struct pointer_to_other< T*, U > -{ + template + struct pointer_to_other< T*, U > + { typedef U* type; -}; - -} // namespace boost + }; +} ``` If these definitions are not correct for a specific smart pointer, we can define a specialization of `pointer_to_other`. diff --git a/doc/smart_ptr/scoped_array.adoc b/doc/smart_ptr/scoped_array.adoc index 74aa96e..73d8a6c 100644 --- a/doc/smart_ptr/scoped_array.adoc +++ b/doc/smart_ptr/scoped_array.adoc @@ -46,12 +46,10 @@ The class template is parameterized on `T`, the type of the object pointed to. `scoped_array` is defined in ``. ``` -namespace boost -{ +namespace boost { -template class scoped_array -{ -private: + template class scoped_array { + private: scoped_array(scoped_array const &); scoped_array & operator=(scoped_array const &); @@ -59,7 +57,7 @@ private: void operator==( scoped_array const& ) const; void operator!=( scoped_array const& ) const; -public: + public: typedef T element_type; @@ -74,17 +72,16 @@ public: explicit operator bool () const noexcept; void swap(scoped_array & b) noexcept; -}; + }; -template void swap(scoped_array & a, scoped_array & b) noexcept; + template void swap(scoped_array & a, scoped_array & b) noexcept; -template bool operator==( scoped_array const & p, std::nullptr_t ) noexcept; -template bool operator==( std::nullptr_t, scoped_array const & p ) noexcept; + template bool operator==( scoped_array const & p, std::nullptr_t ) noexcept; + template bool operator==( std::nullptr_t, scoped_array const & p ) noexcept; -template bool operator!=( scoped_array const & p, std::nullptr_t ) noexcept; -template bool operator!=( std::nullptr_t, scoped_array const & p ) noexcept; - -} // namespace boost + template bool operator!=( scoped_array const & p, std::nullptr_t ) noexcept; + template bool operator!=( std::nullptr_t, scoped_array const & p ) noexcept; +} ``` ## Members diff --git a/doc/smart_ptr/scoped_ptr.adoc b/doc/smart_ptr/scoped_ptr.adoc index dcd616c..8c0bef9 100644 --- a/doc/smart_ptr/scoped_ptr.adoc +++ b/doc/smart_ptr/scoped_ptr.adoc @@ -42,12 +42,10 @@ and `T` must be complete at the point `scoped_ptr::~scoped_ptr` is instantiat `scoped_ptr` is defined in ``. ``` -namespace boost -{ +namespace boost { -template class scoped_ptr -{ -private: + template class scoped_ptr { + private: scoped_ptr(scoped_ptr const&); scoped_ptr& operator=(scoped_ptr const&); @@ -55,7 +53,7 @@ private: void operator==(scoped_ptr const&) const; void operator!=(scoped_ptr const&) const; -public: + public: typedef T element_type; @@ -71,17 +69,16 @@ public: explicit operator bool() const noexcept; void swap(scoped_ptr & b) noexcept; -}; + }; -template void swap(scoped_ptr & a, scoped_ptr & b) noexcept; + template void swap(scoped_ptr & a, scoped_ptr & b) noexcept; -template bool operator==( scoped_ptr const & p, std::nullptr_t ) noexcept; -template bool operator==( std::nullptr_t, scoped_ptr const & p ) noexcept; + template bool operator==( scoped_ptr const & p, std::nullptr_t ) noexcept; + template bool operator==( std::nullptr_t, scoped_ptr const & p ) noexcept; -template bool operator!=( scoped_ptr const & p, std::nullptr_t ) noexcept; -template bool operator!=( std::nullptr_t, scoped_ptr const & p ) noexcept; - -} // namespace boost + template bool operator!=( scoped_ptr const & p, std::nullptr_t ) noexcept; + template bool operator!=( std::nullptr_t, scoped_ptr const & p ) noexcept; +} ``` ## Members diff --git a/doc/smart_ptr/shared_array.adoc b/doc/smart_ptr/shared_array.adoc index e1da95c..5be074c 100644 --- a/doc/smart_ptr/shared_array.adoc +++ b/doc/smart_ptr/shared_array.adoc @@ -52,6 +52,7 @@ below. ``` namespace boost { + template class shared_array { public: typedef T element_type; @@ -237,8 +238,12 @@ Effects::: Exchanges the contents of the two smart pointers. ``` template bool operator==(const shared_array& a, const shared_array& b) noexcept; +``` +``` template bool operator!=(const shared_array& a, const shared_array& b) noexcept; +``` +``` template bool operator<(const shared_array& a, const shared_array& b) noexcept; ``` @@ -261,5 +266,5 @@ template void swap(shared_array& a, shared_array& b) noexcept; ``` :: -Returns::: `a.swap(b)` -Requires::: `T` is a complete type. \ No newline at end of file +Returns::: `a.swap(b)`. +Requires::: `T` is a complete type. diff --git a/doc/smart_ptr/shared_ptr.adoc b/doc/smart_ptr/shared_ptr.adoc index 52aa1be..594c740 100644 --- a/doc/smart_ptr/shared_ptr.adoc +++ b/doc/smart_ptr/shared_ptr.adoc @@ -103,16 +103,14 @@ functions defined in ``. These factory function `shared_ptr` is defined in ``. ``` -namespace boost -{ +namespace boost { -class bad_weak_ptr: public std::exception; + class bad_weak_ptr: public std::exception; -template class weak_ptr; + template class weak_ptr; -template class shared_ptr -{ -public: + template class shared_ptr { + public: typedef /*see below*/ element_type; @@ -182,48 +180,47 @@ public: template bool owner_before(shared_ptr const & rhs) const noexcept; template bool owner_before(weak_ptr const & rhs) const noexcept; -}; + }; -template + template bool operator==(shared_ptr const & a, shared_ptr const & b) noexcept; -template + template bool operator!=(shared_ptr const & a, shared_ptr const & b) noexcept; -template + template bool operator<(shared_ptr const & a, shared_ptr const & b) noexcept; -template bool operator==(shared_ptr const & p, std::nullptr_t) noexcept; -template bool operator==(std::nullptr_t, shared_ptr const & p) noexcept; + template bool operator==(shared_ptr const & p, std::nullptr_t) noexcept; + template bool operator==(std::nullptr_t, shared_ptr const & p) noexcept; -template bool operator!=(shared_ptr const & p, std::nullptr_t) noexcept; -template bool operator!=(std::nullptr_t, shared_ptr const & p) noexcept; + template bool operator!=(shared_ptr const & p, std::nullptr_t) noexcept; + template bool operator!=(std::nullptr_t, shared_ptr const & p) noexcept; -template void swap(shared_ptr & a, shared_ptr & b) noexcept; + template void swap(shared_ptr & a, shared_ptr & b) noexcept; -template + template typename shared_ptr::element_type * - get_pointer(shared_ptr const & p) noexcept; + get_pointer(shared_ptr const & p) noexcept; -template + template shared_ptr static_pointer_cast(shared_ptr const & r) noexcept; -template + template shared_ptr const_pointer_cast(shared_ptr const & r) noexcept; -template + template shared_ptr dynamic_pointer_cast(shared_ptr const & r) noexcept; -template + template shared_ptr reinterpret_pointer_cast(shared_ptr const & r) noexcept; -template + template std::basic_ostream & - operator<< (std::basic_ostream & os, shared_ptr const & p); + operator<< (std::basic_ostream & os, shared_ptr const & p); -template D * get_deleter(shared_ptr const & p) noexcept; - -} // namespace boost + template D * get_deleter(shared_ptr const & p) noexcept; +} ``` ## Members @@ -611,6 +608,8 @@ NOTE: This conversion operator allows `shared_ptr` objects to be used in boolean NOTE: The conversion to `bool` is not merely syntactic sugar. It allows `shared_ptr` variables to be declared in conditions when using `dynamic_pointer_cast` or `weak_ptr::lock`. +NOTE: On C++03 compilers, the return value is of an unspecified type. + ### swap ``` void swap(shared_ptr & b) noexcept; @@ -637,7 +636,7 @@ Effects:: See the description of `operator<`. ### comparison ``` template - bool operator==(shared_ptr const & a, shared_ptr const & b) noexcept; + bool operator==(shared_ptr const & a, shared_ptr const & b) noexcept; ``` [none] * {blank} @@ -646,7 +645,7 @@ Returns:: `a.get() == b.get()`. ``` template - bool operator!=(shared_ptr const & a, shared_ptr const & b) noexcept; + bool operator!=(shared_ptr const & a, shared_ptr const & b) noexcept; ``` [none] * {blank} @@ -677,7 +676,7 @@ Returns:: `p.get() != 0`. ``` template - bool operator<(shared_ptr const & a, shared_ptr const & b) noexcept; + bool operator<(shared_ptr const & a, shared_ptr const & b) noexcept; ``` [none] * {blank} @@ -703,7 +702,7 @@ Effects:: Equivalent to `a.swap(b)`. ### get_pointer ``` template - typename shared_ptr::element_type * + typename shared_ptr::element_type * get_pointer(shared_ptr const & p) noexcept; ``` [none] @@ -716,7 +715,7 @@ NOTE: Provided as an aid to generic programming. Used by `mem_fn`. ### static_pointer_cast ``` template - shared_ptr static_pointer_cast(shared_ptr const & r) noexcept; + shared_ptr static_pointer_cast(shared_ptr const & r) noexcept; ``` [none] * {blank} @@ -730,7 +729,7 @@ result in undefined behavior, attempting to delete the same object twice. ### const_pointer_cast ``` template - shared_ptr const_pointer_cast(shared_ptr const & r) noexcept; + shared_ptr const_pointer_cast(shared_ptr const & r) noexcept; ``` [none] * {blank} @@ -754,7 +753,7 @@ Returns:: ### reinterpret_pointer_cast ``` template - shared_ptr reinterpret_pointer_cast(shared_ptr const & r) noexcept; + shared_ptr reinterpret_pointer_cast(shared_ptr const & r) noexcept; ``` [none] * {blank} @@ -765,7 +764,7 @@ Returns:: `shared_ptr( r, reinterpret_cast::element_ty ### operator<< ``` template - std::basic_ostream & + std::basic_ostream & operator<< (std::basic_ostream & os, shared_ptr const & p); ``` [none] @@ -777,7 +776,7 @@ Returns:: `os`. ### get_deleter ``` template - D * get_deleter(shared_ptr const & p) noexcept; + D * get_deleter(shared_ptr const & p) noexcept; ``` [none] * {blank} diff --git a/doc/smart_ptr/weak_ptr.adoc b/doc/smart_ptr/weak_ptr.adoc index b605949..d51eaa1 100644 --- a/doc/smart_ptr/weak_ptr.adoc +++ b/doc/smart_ptr/weak_ptr.adoc @@ -73,12 +73,10 @@ Now `r` holds a reference to the object that was pointed by `q`. Even if `p.rese `weak_ptr` is defined in ``. ``` -namespace boost -{ +namespace boost { -template class weak_ptr -{ -public: + template class weak_ptr { + public: typedef /*see below*/ element_type; @@ -108,14 +106,13 @@ public: template bool owner_before( weak_ptr const & r ) const noexcept; template bool owner_before( shared_ptr const & r ) const noexcept; -}; + }; -template + template bool operator<(weak_ptr const & a, weak_ptr const & b) noexcept; -template void swap(weak_ptr & a, weak_ptr & b) noexcept; - -} // namespace boost + template void swap(weak_ptr & a, weak_ptr & b) noexcept; +} ``` ## Members @@ -250,7 +247,7 @@ Returns:: See the description of `operator<`. ### comparison ``` template - bool operator<(weak_ptr const & a, weak_ptr const & b) noexcept; + bool operator<(weak_ptr const & a, weak_ptr const & b) noexcept; ``` [none] * {blank}