Merged revision(s) 81368, 81399, 81407-81409, 81419, 81430-81431, 81437 from trunk:

Apply BOOST_NOEXCEPT patch. Refs #7523.
........
Replace std::forward with detail::sp_forward.
........
Cosmetic changes in make_shared_array.hpp and allocate_shared_array.hpp
........
Documentation of make_shared_array: Minor corrections
........
Make make_shared_array.hpp and allocate_shared_array.hpp consistent with namespace qualification in rest of smart_ptr.
........
Update smart_ptr.htm with link to make_shared_array.htm which lists the many overloads of make_shared and allocate_shared for arrays.
........
Update documentation for make_shared and allocate_shared array forms.
........
Minor corrections in make_shared_array.html documentation.
........
Borland fixes.
........


[SVN r81457]
This commit is contained in:
Peter Dimov
2012-11-21 15:38:06 +00:00
parent 215771c83d
commit c7b6e56b30
16 changed files with 448 additions and 317 deletions

View File

@ -13,6 +13,7 @@
#include <boost/smart_ptr/detail/allocate_array_helper.hpp>
#include <boost/smart_ptr/detail/array_deleter.hpp>
#include <boost/smart_ptr/detail/array_traits.hpp>
#include <boost/smart_ptr/detail/sp_forward.hpp>
#include <boost/smart_ptr/detail/sp_if_array.hpp>
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
#include <initializer_list>
@ -20,146 +21,146 @@
namespace boost {
template<typename T, typename A>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator, std::size_t size) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * detail::array_total<T1>::size;
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct(p2, n1);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
template<typename T, typename A, typename... Args>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator, std::size_t size, Args&&... args) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * detail::array_total<T1>::size;
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, std::forward<Args>(args)...);
return shared_ptr<T>(s1, p1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename A, typename... Args>
inline typename detail::sp_if_size_array<T>::type
inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared(const A& allocator, Args&&... args) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = detail::array_total<T>::size;
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = boost::detail::array_total<T>::size;
boost::detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, std::forward<Args>(args)...);
return shared_ptr<T>(s1, p1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
#endif
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
template<typename T, typename A>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator,
std::initializer_list<typename detail::array_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n1 = list.size() * detail::array_total<T1>::size;
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = list.size() * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename A>
inline typename detail::sp_if_size_array<T>::type
inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared(const A& allocator,
std::initializer_list<typename detail::array_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
BOOST_ASSERT(list.size() == detail::array_size<T>::size);
BOOST_ASSERT(list.size() == boost::detail::array_size<T>::size);
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n1 = detail::array_total<T>::size;
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = boost::detail::array_total<T>::size;
boost::detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename A>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator, std::size_t size,
std::initializer_list<typename detail::arrays_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n0 = detail::array_total<T1>::size;
std::size_t n0 = boost::detail::array_total<T1>::size;
std::size_t n1 = n0 * list.size();
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
boost::detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3, n0);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename A>
inline typename detail::sp_if_size_array<T>::type
inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared(const A& allocator,
std::initializer_list<typename detail::arrays_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
BOOST_ASSERT(list.size() == detail::array_size<T1>::size);
BOOST_ASSERT(list.size() == boost::detail::array_size<T1>::size);
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n0 = detail::array_total<T1>::size;
std::size_t n1 = detail::array_total<T>::size;
detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n0 = boost::detail::array_total<T1>::size;
std::size_t n1 = boost::detail::array_total<T>::size;
boost::detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3, n0);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
#endif
}

View File

@ -57,7 +57,7 @@ namespace boost {
return allocator.max_size();
}
pointer allocate(size_type count, const void* value = 0) {
std::size_t a1 = alignment_of<T>::value;
std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1;
char* p1 = A3(allocator).allocate(n1 + size, value);
char* p2 = p1 + n1;
@ -68,7 +68,7 @@ namespace boost {
return reinterpret_cast<Y*>(p1);
}
void deallocate(pointer memory, size_type count) {
std::size_t a1 = alignment_of<T>::value;
std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1;
char* p1 = reinterpret_cast<char*>(memory);
A3(allocator).deallocate(p1, n1 + size);

View File

@ -52,7 +52,7 @@ namespace boost {
return static_cast<std::size_t>(-1) / sizeof(Y);
}
pointer allocate(size_type count, const void* = 0) {
std::size_t a1 = alignment_of<T>::value;
std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1;
void* p1 = ::operator new(n1 + size);
char* p2 = static_cast<char*>(p1) + n1;

View File

@ -8,7 +8,7 @@
#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
operator bool () const
operator bool () const BOOST_NOEXCEPT
{
return px != 0;
}
@ -21,7 +21,7 @@
typedef void (*unspecified_bool_type)( this_type*** );
operator unspecified_bool_type() const // never throws
operator unspecified_bool_type() const BOOST_NOEXCEPT
{
return px == 0? 0: unspecified_bool;
}
@ -33,7 +33,7 @@
typedef element_type * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
operator unspecified_bool_type() const BOOST_NOEXCEPT
{
return px == 0? 0: &this_type::get;
}
@ -42,7 +42,7 @@
typedef element_type * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
operator unspecified_bool_type() const BOOST_NOEXCEPT
{
return px == 0? 0: &this_type::px;
}
@ -50,7 +50,7 @@
#endif
// operator! is redundant, but some compilers need it
bool operator! () const // never throws
bool operator! () const BOOST_NOEXCEPT
{
return px == 0;
}

View File

@ -0,0 +1,39 @@
#ifndef BOOST_SMART_PTR_DETAIL_SP_FORWARD_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_SP_FORWARD_HPP_INCLUDED
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
// detail/sp_forward.hpp
//
// Copyright 2008,2012 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/config.hpp>
namespace boost
{
namespace detail
{
#if defined( BOOST_HAS_RVALUE_REFS )
template< class T > T&& sp_forward( T & t ) BOOST_NOEXCEPT
{
return static_cast< T&& >( t );
}
#endif
} // namespace detail
} // namespace boost
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_FORWARD_HPP_INCLUDED

View File

@ -25,20 +25,20 @@ template<class T> class enable_shared_from_this
{
protected:
enable_shared_from_this()
enable_shared_from_this() BOOST_NOEXCEPT
{
}
enable_shared_from_this(enable_shared_from_this const &)
enable_shared_from_this(enable_shared_from_this const &) BOOST_NOEXCEPT
{
}
enable_shared_from_this & operator=(enable_shared_from_this const &)
enable_shared_from_this & operator=(enable_shared_from_this const &) BOOST_NOEXCEPT
{
return *this;
}
~enable_shared_from_this()
~enable_shared_from_this() BOOST_NOEXCEPT // ~weak_ptr<T> newer throws, so this call also must not throw
{
}

View File

@ -58,7 +58,7 @@ public:
typedef T element_type;
intrusive_ptr(): px( 0 )
intrusive_ptr() BOOST_NOEXCEPT : px( 0 )
{
}
@ -110,12 +110,12 @@ public:
#if defined( BOOST_HAS_RVALUE_REFS )
intrusive_ptr(intrusive_ptr && rhs): px( rhs.px )
intrusive_ptr(intrusive_ptr && rhs) BOOST_NOEXCEPT : px( rhs.px )
{
rhs.px = 0;
}
intrusive_ptr & operator=(intrusive_ptr && rhs)
intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_NOEXCEPT
{
this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this);
return *this;
@ -135,7 +135,7 @@ public:
return *this;
}
void reset()
void reset() BOOST_NOEXCEPT
{
this_type().swap( *this );
}
@ -145,7 +145,7 @@ public:
this_type( rhs ).swap( *this );
}
T * get() const
T * get() const BOOST_NOEXCEPT
{
return px;
}
@ -165,7 +165,7 @@ public:
// implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
void swap(intrusive_ptr & rhs)
void swap(intrusive_ptr & rhs) BOOST_NOEXCEPT
{
T * tmp = px;
px = rhs.px;

View File

@ -13,6 +13,7 @@
#include <boost/smart_ptr/detail/array_deleter.hpp>
#include <boost/smart_ptr/detail/array_traits.hpp>
#include <boost/smart_ptr/detail/make_array_helper.hpp>
#include <boost/smart_ptr/detail/sp_forward.hpp>
#include <boost/smart_ptr/detail/sp_if_array.hpp>
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
#include <initializer_list>
@ -20,178 +21,178 @@
namespace boost {
template<typename T>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
make_shared(std::size_t size) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * detail::array_total<T1>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct(p2, n1);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
template<typename T, typename... Args>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
make_shared(std::size_t size, Args&&... args) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * detail::array_total<T1>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, std::forward<Args>(args)...);
return shared_ptr<T>(s1, p1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename... Args>
inline typename detail::sp_if_size_array<T>::type
inline typename boost::detail::sp_if_size_array<T>::type
make_shared(Args&&... args) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = detail::array_total<T>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = boost::detail::array_total<T>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, std::forward<Args>(args)...);
return shared_ptr<T>(s1, p1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct(p2, n1, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
#endif
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
template<typename T>
inline typename detail::sp_if_array<T>::type
make_shared(std::initializer_list<typename detail::array_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
inline typename boost::detail::sp_if_array<T>::type
make_shared(std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n1 = list.size() * detail::array_total<T1>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = list.size() * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T>
inline typename detail::sp_if_size_array<T>::type
make_shared(std::initializer_list<typename detail::array_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
inline typename boost::detail::sp_if_size_array<T>::type
make_shared(std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
BOOST_ASSERT(list.size() == detail::array_size<T>::size);
BOOST_ASSERT(list.size() == boost::detail::array_size<T>::size);
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n1 = detail::array_total<T>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = boost::detail::array_total<T>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
make_shared(std::size_t size,
std::initializer_list<typename detail::arrays_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n0 = detail::array_total<T1>::size;
std::size_t n0 = boost::detail::array_total<T1>::size;
std::size_t n1 = n0 * size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3, n0);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T>
inline typename detail::sp_if_size_array<T>::type
make_shared(std::initializer_list<typename detail::arrays_inner<T>::type> list) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
inline typename boost::detail::sp_if_size_array<T>::type
make_shared(std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
BOOST_ASSERT(list.size() == detail::array_size<T1>::size);
BOOST_ASSERT(list.size() == boost::detail::array_size<T1>::size);
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n0 = detail::array_total<T1>::size;
std::size_t n1 = detail::array_total<T>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n0 = boost::detail::array_total<T1>::size;
std::size_t n1 = boost::detail::array_total<T>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_list(p2, n1, p3, n0);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
#endif
template<typename T>
inline typename detail::sp_if_array<T>::type
inline typename boost::detail::sp_if_array<T>::type
make_shared_noinit(std::size_t size) {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * detail::array_total<T1>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_noinit(p2, n1);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T>
inline typename detail::sp_if_size_array<T>::type
inline typename boost::detail::sp_if_size_array<T>::type
make_shared_noinit() {
typedef typename detail::array_inner<T>::type T1;
typedef typename detail::array_base<T1>::type T2;
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = detail::array_total<T>::size;
detail::make_array_helper<T2> a1(n1, &p2);
detail::array_deleter<T2> d1;
shared_ptr<T> s1(p1, d1, a1);
detail::array_deleter<T2>* d2;
std::size_t n1 = boost::detail::array_total<T>::size;
boost::detail::make_array_helper<T2> a1(n1, &p2);
boost::detail::array_deleter<T2> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
boost::detail::array_deleter<T2>* d2;
p1 = reinterpret_cast<T1*>(p2);
d2 = get_deleter<detail::array_deleter<T2> >(s1);
d2 = get_deleter<boost::detail::array_deleter<T2> >(s1);
d2->construct_noinit(p2, n1);
return shared_ptr<T>(s1, p1);
return boost::shared_ptr<T>(s1, p1);
}
}

View File

@ -14,6 +14,7 @@
#include <boost/config.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/detail/sp_forward.hpp>
#include <boost/type_traits/type_with_alignment.hpp>
#include <boost/type_traits/alignment_of.hpp>
#include <cstddef>
@ -67,12 +68,12 @@ private:
public:
sp_ms_deleter(): initialized_( false )
sp_ms_deleter() BOOST_NOEXCEPT : initialized_( false )
{
}
// optimization: do not copy storage_
sp_ms_deleter( sp_ms_deleter const & ): initialized_( false )
sp_ms_deleter( sp_ms_deleter const & ) BOOST_NOEXCEPT : initialized_( false )
{
}
@ -86,26 +87,17 @@ public:
destroy();
}
void * address()
void * address() BOOST_NOEXCEPT
{
return storage_.data_;
}
void set_initialized()
void set_initialized() BOOST_NOEXCEPT
{
initialized_ = true;
}
};
#if defined( BOOST_HAS_RVALUE_REFS )
template< class T > T&& sp_forward( T & t )
{
return static_cast< T&& >( t );
}
#endif
template< class T > struct sp_if_not_array
{
typedef boost::shared_ptr< T > type;
@ -117,12 +109,16 @@ template< class T > struct sp_if_not_array< T[] >
{
};
#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
template< class T, std::size_t N > struct sp_if_not_array< T[N] >
{
};
#endif
#endif
} // namespace detail
#if !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )

View File

@ -53,7 +53,7 @@ public:
typedef T element_type;
explicit scoped_array( T * p = 0 ) : px( p ) // never throws
explicit scoped_array( T * p = 0 ) BOOST_NOEXCEPT : px( p )
{
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_array_constructor_hook( px );
@ -68,20 +68,20 @@ public:
boost::checked_array_delete( px );
}
void reset(T * p = 0) // never throws
void reset(T * p = 0) // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
{
BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
this_type(p).swap(*this);
}
T & operator[](std::ptrdiff_t i) const // never throws
T & operator[](std::ptrdiff_t i) const // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
{
BOOST_ASSERT( px != 0 );
BOOST_ASSERT( i >= 0 );
return px[i];
}
T * get() const // never throws
T * get() const BOOST_NOEXCEPT
{
return px;
}
@ -89,7 +89,7 @@ public:
// implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
void swap(scoped_array & b) // never throws
void swap(scoped_array & b) BOOST_NOEXCEPT
{
T * tmp = b.px;
b.px = px;
@ -97,7 +97,7 @@ public:
}
};
template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) // never throws
template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) BOOST_NOEXCEPT
{
a.swap(b);
}

View File

@ -63,7 +63,7 @@ public:
#ifndef BOOST_NO_AUTO_PTR
explicit scoped_ptr( std::auto_ptr<T> p ): px( p.release() ) // never throws
explicit scoped_ptr( std::auto_ptr<T> p ) BOOST_NOEXCEPT : px( p.release() )
{
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_scalar_constructor_hook( px );
@ -98,7 +98,7 @@ public:
return px;
}
T * get() const // never throws
T * get() const BOOST_NOEXCEPT
{
return px;
}
@ -106,7 +106,7 @@ public:
// implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
void swap(scoped_ptr & b) // never throws
void swap(scoped_ptr & b) BOOST_NOEXCEPT
{
T * tmp = b.px;
b.px = px;
@ -114,14 +114,14 @@ public:
}
};
template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) // never throws
template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) BOOST_NOEXCEPT
{
a.swap(b);
}
// get_pointer(p) is a generic way to say p.get()
template<class T> inline T * get_pointer(scoped_ptr<T> const & p)
template<class T> inline T * get_pointer(scoped_ptr<T> const & p) BOOST_NOEXCEPT
{
return p.get();
}

View File

@ -56,7 +56,7 @@ public:
typedef T element_type;
shared_array(): px( 0 ), pn() // never throws
shared_array() BOOST_NOEXCEPT : px( 0 ), pn()
{
}
@ -90,11 +90,11 @@ public:
// ... except in C++0x, move disables the implicit copy
shared_array( shared_array const & r ): px( r.px ), pn( r.pn ) // never throws
shared_array( shared_array const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
{
}
shared_array( shared_array && r ): px( r.px ), pn() // never throws
shared_array( shared_array && r ) BOOST_NOEXCEPT : px( r.px ), pn()
{
pn.swap( r.pn );
r.px = 0;
@ -114,7 +114,7 @@ public:
shared_array( shared_array<Y> const & r )
#endif
: px( r.px ), pn( r.pn ) // never throws
BOOST_NOEXCEPT : px( r.px ), pn( r.pn ) // never throws
{
boost::detail::sp_assert_convertible< Y[], T[] >();
}
@ -122,13 +122,13 @@ public:
// aliasing
template< class Y >
shared_array( shared_array<Y> const & r, element_type * p ): px( p ), pn( r.pn ) // never throws
shared_array( shared_array<Y> const & r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn( r.pn )
{
}
// assignment
shared_array & operator=( shared_array const & r ) // never throws
shared_array & operator=( shared_array const & r ) BOOST_NOEXCEPT
{
this_type( r ).swap( *this );
return *this;
@ -137,7 +137,7 @@ public:
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
template<class Y>
shared_array & operator=( shared_array<Y> const & r ) // never throws
shared_array & operator=( shared_array<Y> const & r ) BOOST_NOEXCEPT
{
this_type( r ).swap( *this );
return *this;
@ -147,14 +147,14 @@ public:
#if defined( BOOST_HAS_RVALUE_REFS )
shared_array & operator=( shared_array && r ) // never throws
shared_array & operator=( shared_array && r ) BOOST_NOEXCEPT
{
this_type( static_cast< shared_array && >( r ) ).swap( *this );
return *this;
}
template<class Y>
shared_array & operator=( shared_array<Y> && r ) // never throws
shared_array & operator=( shared_array<Y> && r ) BOOST_NOEXCEPT
{
this_type( static_cast< shared_array<Y> && >( r ) ).swap( *this );
return *this;
@ -162,7 +162,7 @@ public:
#endif
void reset() // never throws
void reset() BOOST_NOEXCEPT
{
this_type().swap( *this );
}
@ -188,14 +188,14 @@ public:
this_type( r, p ).swap( *this );
}
T & operator[] (std::ptrdiff_t i) const // never throws
T & operator[] (std::ptrdiff_t i) const // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
{
BOOST_ASSERT(px != 0);
BOOST_ASSERT(i >= 0);
return px[i];
}
T * get() const // never throws
T * get() const BOOST_NOEXCEPT
{
return px;
}
@ -203,17 +203,17 @@ public:
// implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
bool unique() const // never throws
bool unique() const BOOST_NOEXCEPT
{
return pn.unique();
}
long use_count() const // never throws
long use_count() const BOOST_NOEXCEPT
{
return pn.use_count();
}
void swap(shared_array<T> & other) // never throws
void swap(shared_array<T> & other) BOOST_NOEXCEPT
{
std::swap(px, other.px);
pn.swap(other.pn);
@ -233,22 +233,22 @@ private:
}; // shared_array
template<class T> inline bool operator==(shared_array<T> const & a, shared_array<T> const & b) // never throws
template<class T> inline bool operator==(shared_array<T> const & a, shared_array<T> const & b) BOOST_NOEXCEPT
{
return a.get() == b.get();
}
template<class T> inline bool operator!=(shared_array<T> const & a, shared_array<T> const & b) // never throws
template<class T> inline bool operator!=(shared_array<T> const & a, shared_array<T> const & b) BOOST_NOEXCEPT
{
return a.get() != b.get();
}
template<class T> inline bool operator<(shared_array<T> const & a, shared_array<T> const & b) // never throws
template<class T> inline bool operator<(shared_array<T> const & a, shared_array<T> const & b) BOOST_NOEXCEPT
{
return std::less<T*>()(a.get(), b.get());
}
template<class 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) BOOST_NOEXCEPT
{
a.swap(b);
}

View File

@ -81,11 +81,15 @@ template< class T > struct sp_element< T[] >
typedef T type;
};
#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
template< class T, std::size_t N > struct sp_element< T[N] >
{
typedef T type;
};
#endif
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
// sp_dereference, return type of operator*
@ -126,11 +130,15 @@ template< class T > struct sp_dereference< T[] >
typedef void type;
};
#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
template< class T, std::size_t N > struct sp_dereference< T[N] >
{
typedef void type;
};
#endif
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
// sp_member_access, return type of operator->
@ -147,11 +155,15 @@ template< class T > struct sp_member_access< T[] >
typedef void type;
};
#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
template< class T, std::size_t N > struct sp_member_access< T[N] >
{
typedef void type;
};
#endif
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
// sp_array_access, return type of operator[]
@ -168,11 +180,15 @@ template< class T > struct sp_array_access< T[] >
typedef T & type;
};
#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
template< class T, std::size_t N > struct sp_array_access< T[N] >
{
typedef T & type;
};
#endif
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
// sp_extent, for operator[] index check
@ -324,7 +340,7 @@ public:
typedef typename boost::detail::sp_element< T >::type element_type;
shared_ptr(): px( 0 ), pn() // never throws in 1.30+
shared_ptr() BOOST_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
{
}
@ -358,7 +374,7 @@ public:
// ... except in C++0x, move disables the implicit copy
shared_ptr( shared_ptr const & r ): px( r.px ), pn( r.pn ) // never throws
shared_ptr( shared_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
{
}
@ -374,7 +390,8 @@ public:
}
template<class Y>
shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag ): px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() ) // never throws
shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag )
BOOST_NOEXCEPT : px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() )
{
if( !pn.empty() )
{
@ -392,24 +409,26 @@ public:
shared_ptr( shared_ptr<Y> const & r )
#endif
: px( r.px ), pn( r.pn ) // never throws
BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
{
boost::detail::sp_assert_convertible< Y, T >();
}
// aliasing
template< class Y >
shared_ptr( shared_ptr<Y> const & r, element_type * p ): px( p ), pn( r.pn ) // never throws
shared_ptr( shared_ptr<Y> const & r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn( r.pn )
{
}
template<class Y>
shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag)
BOOST_NOEXCEPT : px(static_cast<element_type *>(r.px)), pn(r.pn)
{
}
template<class Y>
shared_ptr(shared_ptr<Y> const & r, boost::detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
shared_ptr(shared_ptr<Y> const & r, boost::detail::const_cast_tag)
BOOST_NOEXCEPT : px(const_cast<element_type *>(r.px)), pn(r.pn)
{
}
@ -480,7 +499,7 @@ public:
// assignment
shared_ptr & operator=( shared_ptr const & r ) // never throws
shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
{
this_type(r).swap(*this);
return *this;
@ -489,7 +508,7 @@ public:
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
template<class Y>
shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
shared_ptr & operator=(shared_ptr<Y> const & r) BOOST_NOEXCEPT
{
this_type(r).swap(*this);
return *this;
@ -523,7 +542,7 @@ public:
#if defined( BOOST_HAS_RVALUE_REFS )
shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws
shared_ptr( shared_ptr && r ) BOOST_NOEXCEPT : px( r.px ), pn()
{
pn.swap( r.pn );
r.px = 0;
@ -539,7 +558,7 @@ public:
shared_ptr( shared_ptr<Y> && r )
#endif
: px( r.px ), pn() // never throws
BOOST_NOEXCEPT : px( r.px ), pn()
{
boost::detail::sp_assert_convertible< Y, T >();
@ -547,14 +566,14 @@ public:
r.px = 0;
}
shared_ptr & operator=( shared_ptr && r ) // never throws
shared_ptr & operator=( shared_ptr && r ) BOOST_NOEXCEPT
{
this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
return *this;
}
template<class Y>
shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
shared_ptr & operator=( shared_ptr<Y> && r ) BOOST_NOEXCEPT
{
this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
return *this;
@ -562,7 +581,7 @@ public:
#endif
void reset() // never throws in 1.30+
void reset() BOOST_NOEXCEPT // never throws in 1.30+
{
this_type().swap(*this);
}
@ -587,20 +606,23 @@ public:
{
this_type( r, p ).swap( *this );
}
typename boost::detail::sp_dereference< T >::type operator* () const // never throws
// never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
typename boost::detail::sp_dereference< T >::type operator* () const
{
BOOST_ASSERT( px != 0 );
return *px;
}
typename boost::detail::sp_member_access< T >::type operator-> () const // never throws
// never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
typename boost::detail::sp_member_access< T >::type operator-> () const
{
BOOST_ASSERT( px != 0 );
return px;
}
typename boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const // never throws
// never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
typename boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const
{
BOOST_ASSERT( px != 0 );
BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
@ -608,7 +630,7 @@ public:
return px[ i ];
}
element_type * get() const // never throws
element_type * get() const BOOST_NOEXCEPT
{
return px;
}
@ -616,28 +638,28 @@ public:
// implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
bool unique() const // never throws
bool unique() const BOOST_NOEXCEPT
{
return pn.unique();
}
long use_count() const // never throws
long use_count() const BOOST_NOEXCEPT
{
return pn.use_count();
}
void swap( shared_ptr & other ) // never throws
void swap( shared_ptr & other ) BOOST_NOEXCEPT
{
std::swap(px, other.px);
pn.swap(other.pn);
}
template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const
template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
{
return pn < rhs.pn;
}
template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const
template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
{
return pn < rhs.pn;
}
@ -647,7 +669,7 @@ public:
return pn.get_deleter( ti );
}
bool _internal_equiv( shared_ptr const & r ) const
bool _internal_equiv( shared_ptr const & r ) const BOOST_NOEXCEPT
{
return px == r.px && pn == r.pn;
}
@ -670,12 +692,12 @@ private:
}; // shared_ptr
template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)
template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
{
return a.get() == b.get();
}
template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b)
template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
{
return a.get() != b.get();
}
@ -684,19 +706,19 @@ template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, share
// Resolve the ambiguity between our op!= and the one in rel_ops
template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b)
template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b) BOOST_NOEXCEPT
{
return a.get() != b.get();
}
#endif
template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)
template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
{
return a.owner_before( b );
}
template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b) BOOST_NOEXCEPT
{
a.swap(b);
}
@ -741,7 +763,7 @@ template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<
// get_pointer() enables boost::mem_fn to recognize shared_ptr
template<class T> inline T * get_pointer(shared_ptr<T> const & p)
template<class T> inline T * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
{
return p.get();
}
@ -854,7 +876,7 @@ template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ )
template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ ) BOOST_NOEXCEPT
{
return false;
}
@ -933,7 +955,7 @@ template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> *
template< class T > struct hash;
template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p )
template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT
{
return boost::hash< T* >()( p.get() );
}

View File

@ -31,7 +31,7 @@ public:
typedef typename boost::detail::sp_element< T >::type element_type;
weak_ptr(): px(0), pn() // never throws in 1.30+
weak_ptr() BOOST_NOEXCEPT : px(0), pn() // never throws in 1.30+
{
}
@ -41,11 +41,11 @@ public:
// ... except in C++0x, move disables the implicit copy
weak_ptr( weak_ptr const & r ): px( r.px ), pn( r.pn ) // never throws
weak_ptr( weak_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
{
}
weak_ptr & operator=( weak_ptr const & r ) // never throws
weak_ptr & operator=( weak_ptr const & r ) BOOST_NOEXCEPT
{
px = r.px;
pn = r.pn;
@ -81,7 +81,7 @@ public:
weak_ptr( weak_ptr<Y> const & r )
#endif
: px(r.lock().get()), pn(r.pn) // never throws
BOOST_NOEXCEPT : px(r.lock().get()), pn(r.pn)
{
boost::detail::sp_assert_convertible< Y, T >();
}
@ -98,20 +98,21 @@ public:
weak_ptr( weak_ptr<Y> && r )
#endif
: px( r.lock().get() ), pn( static_cast< boost::detail::weak_count && >( r.pn ) ) // never throws
BOOST_NOEXCEPT : px( r.lock().get() ), pn( static_cast< boost::detail::weak_count && >( r.pn ) )
{
boost::detail::sp_assert_convertible< Y, T >();
r.px = 0;
}
// for better efficiency in the T == Y case
weak_ptr( weak_ptr && r ): px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) ) // never throws
weak_ptr( weak_ptr && r )
BOOST_NOEXCEPT : px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) )
{
r.px = 0;
}
// for better efficiency in the T == Y case
weak_ptr & operator=( weak_ptr && r ) // never throws
weak_ptr & operator=( weak_ptr && r ) BOOST_NOEXCEPT
{
this_type( static_cast< weak_ptr && >( r ) ).swap( *this );
return *this;
@ -130,7 +131,7 @@ public:
weak_ptr( shared_ptr<Y> const & r )
#endif
: px( r.px ), pn( r.pn ) // never throws
BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
{
boost::detail::sp_assert_convertible< Y, T >();
}
@ -138,7 +139,7 @@ public:
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
template<class Y>
weak_ptr & operator=( weak_ptr<Y> const & r ) // never throws
weak_ptr & operator=( weak_ptr<Y> const & r ) BOOST_NOEXCEPT
{
boost::detail::sp_assert_convertible< Y, T >();
@ -151,7 +152,7 @@ public:
#if defined( BOOST_HAS_RVALUE_REFS )
template<class Y>
weak_ptr & operator=( weak_ptr<Y> && r )
weak_ptr & operator=( weak_ptr<Y> && r ) BOOST_NOEXCEPT
{
this_type( static_cast< weak_ptr<Y> && >( r ) ).swap( *this );
return *this;
@ -160,7 +161,7 @@ public:
#endif
template<class Y>
weak_ptr & operator=( shared_ptr<Y> const & r ) // never throws
weak_ptr & operator=( shared_ptr<Y> const & r ) BOOST_NOEXCEPT
{
boost::detail::sp_assert_convertible< Y, T >();
@ -172,17 +173,17 @@ public:
#endif
shared_ptr<T> lock() const // never throws
shared_ptr<T> lock() const BOOST_NOEXCEPT
{
return shared_ptr<T>( *this, boost::detail::sp_nothrow_tag() );
}
long use_count() const // never throws
long use_count() const BOOST_NOEXCEPT
{
return pn.use_count();
}
bool expired() const // never throws
bool expired() const BOOST_NOEXCEPT
{
return pn.use_count() == 0;
}
@ -192,12 +193,12 @@ public:
return pn.empty();
}
void reset() // never throws in 1.30+
void reset() BOOST_NOEXCEPT // never throws in 1.30+
{
this_type().swap(*this);
}
void swap(this_type & other) // never throws
void swap(this_type & other) BOOST_NOEXCEPT
{
std::swap(px, other.px);
pn.swap(other.pn);
@ -210,12 +211,12 @@ public:
pn = r.pn;
}
template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const
template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
{
return pn < rhs.pn;
}
template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const
template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
{
return pn < rhs.pn;
}
@ -237,12 +238,12 @@ private:
}; // weak_ptr
template<class T, class U> inline bool operator<(weak_ptr<T> const & a, weak_ptr<U> const & b)
template<class T, class U> inline bool operator<(weak_ptr<T> const & a, weak_ptr<U> const & b) BOOST_NOEXCEPT
{
return a.owner_before( b );
}
template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b)
template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b) BOOST_NOEXCEPT
{
a.swap(b);
}

View File

@ -12,12 +12,14 @@
<A href="#Synopsis">Synopsis</A><br>
<A href="#functions">Free Functions</A><br>
<A href="#example">Example</A><br>
<A href="#history">History</A><br>
<h2><a name="Introduction">Introduction</a></h2>
<p>One criticism of Boost <a href="shared_array.htm">shared_array</a> is
the lack of utility similar to <a href="make_shared.htm">make_shared</a>
which ensures only a single allocation for an array. A second criticism
is Boost <code>shared_array</code> does not support custom allocators
and so also lacks an <code>allocate_shared</code> utility.</p>
<p>Originally the Boost function templates <code>make_shared</code> and
<code>allocate_shared</code> were for efficient allocation of single
objects only. There was a need to have efficient, single, allocation of
arrays. One criticism of <a href="shared_array.htm">shared_array</a> was
always the lack of a <a href="make_shared.htm">make_shared</a> utility
which ensures only a single allocation for an array.</p>
<p>The header files &lt;boost/smart_ptr/make_shared_array.hpp&gt; and
&lt;boost/smart_ptr/allocate_shared_array.hpp&gt; provide new function
templates, <code>make_shared</code> and <code>allocate_shared</code>,
@ -32,17 +34,17 @@
template&lt;typename T, typename A&gt;
shared_ptr&lt;T[]&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size);
#if defined(BOOST_HAS_VARIADIC_TMPL) &amp;&amp; defined(BOOST_HAS_RVALUE_REFS)
template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[]&gt; <a href="#functions">make_shared</a>(size_t size, Args&amp;&amp;... args);
template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[N]&gt; <a href="#functions">make_shared</a>(Args&amp;&amp;... args);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size, Args&amp;&amp;... args);
shared_ptr&lt;T[]&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size, Args&amp;&amp;... args);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[N]&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, Args&amp;&amp;... args);
#endif
@ -50,40 +52,40 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[]&gt; <a href="#functions">make_shared</a>(initializer_list&lt;T&gt; list);
template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[N]&gt; <a href="#functions">make_shared</a>(initializer_list&lt;T&gt; list);
template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[][N]&gt; <a href="#functions">make_shared</a>(size_t size, initializer_list&lt;T&gt; list);
template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[M][N]&gt; <a href="#functions">make_shared</a>(initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[]&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[N]&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[][N]&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size, initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[M][N]&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, initializer_list&lt;T&gt; list);
#endif
template&lt;typename T&gt;
shared_ptr&lt;T&gt; <a href="#functions">make_shared_noinit</a>(size_t size);
shared_ptr&lt;T[]&gt; <a href="#functions">make_shared_noinit</a>(size_t size);
template&lt;typename T&gt;
shared_ptr&lt;T[N]&gt; <a href="#functions">make_shared_noinit</a>();
}</pre>
<h2><a name="functions">Free Functions</a></h2>
<pre>template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T&gt; make_shared(size_t size, Args&amp;&amp;... args);
shared_ptr&lt;T[]&gt; make_shared(size_t size, Args&amp;&amp;... args);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T&gt; allocate_shared(const A&amp; allocator, size_t size, Args&amp;&amp;... args);</pre>
shared_ptr&lt;T[]&gt; allocate_shared(const A&amp; allocator, size_t size, Args&amp;&amp;... args);</pre>
<blockquote>
<p><b>Requires:</b> The expression
<code>new(pointer) T(forward&lt;Args&gt;(args)...)</code>, where
@ -122,16 +124,74 @@ template&lt;typename T, typename A, typename... Args&gt;
take any constructor arguments. These overloads invoke the default
constructor of <code>T</code> for each array element.</p>
</blockquote>
<pre>template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[N]&gt; make_shared(Args&amp;&amp;... args);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[N]&gt; allocate_shared(const A&amp; allocator, Args&amp;&amp;... args);</pre>
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<pre>template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[]&gt; make_shared(initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[]&gt; allocate_shared(const A&amp; allocator, initializer_list&lt;T&gt; list);</pre>
<blockquote>
<p><b>Description:</b> These overloads initialize the array elements
from the initializer list.</p>
</blockquote>
<pre>template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[N]&gt; make_shared(initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[N]&gt; allocate_shared(const A&amp; allocator, initializer_list&lt;T&gt; list);</pre>
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<pre>template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[][N]&gt; make_shared(size_t size, initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[][N]&gt; allocate_shared(const A&amp; allocator, size_t size, initializer_list&lt;T&gt; list);</pre>
<blockquote>
<p><b>Description:</b> These overloads initialize inner array elements
from the initializer list.</p>
</blockquote>
<pre>template&lt;typename T, typename... Args&gt;
shared_ptr&lt;T[M][N]&gt; make_shared(initializer_list&lt;T&gt; list);
template&lt;typename T, typename A, typename... Args&gt;
shared_ptr&lt;T[M][N]&gt; allocate_shared(const A&amp; allocator, initializer_list&lt;T&gt; list);</pre>
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<pre>template&lt;typename T&gt;
shared_ptr&lt;T[]&gt; make_shared_noinit(size_t size);</pre>
<blockquote>
<p><b>Description:</b> This overload does not perform value
initialization of elements.</p>
</blockquote>
<pre>template&lt;typename T&gt;
shared_ptr&lt;T[N]&gt; make_shared_noinit();</pre>
<blockquote>
<p><b>Description:</b> This overload of the utility above is used for a
fixed size array.</p>
</blockquote>
<h2><a name="example">Example</a></h2>
<pre>boost::shared_ptr&lt;int[]&gt; a1 = boost::make_shared&lt;int[]&gt;(size);
boost::shared_ptr&lt;point[5]&gt; a2 = boost::make_shared&lt;point[5]&gt;(x, y);
boost::shared_ptr&lt;int[5]&gt; a3 = boost::make_shared&lt;int[5]&gt;();
<p>An example of each overload of make_shared for arrays:</p>
<blockquote>
<pre>boost::shared_ptr&lt;point[]&gt; a1 = boost::make_shared&lt;point[]&gt;(size);
boost::shared_ptr&lt;point[]&gt; a2 = boost::make_shared&lt;point[]&gt;(size, x, y);
boost::shared_ptr&lt;point[5]&gt; a3 = boost::make_shared&lt;point[5]&gt;(x, y);
boost::shared_ptr&lt;int[]&gt; a4 = boost::make_shared&lt;int[]&gt;({1, 2, 3});
boost::shared_ptr&lt;int[3]&gt; a5 = boost::make_shared&lt;int[3]&gt;({1, 2, 3});
boost::shared_ptr&lt;int[][3]&gt; a6 = boost::make_shared&lt;int[][3]&gt;(size, {1, 2, 3});
boost::shared_ptr&lt;int[5][3]&gt; a7 = boost::make_shared&lt;int[5][3]&gt;({1, 2, 3});
boost::shared_ptr&lt;int[]&gt; a8 = boost::make_shared_noinit&lt;int[]&gt;(size);
boost::shared_ptr&lt;int[5]&gt; a9 = boost::make_shared_noinit&lt;int[5]&gt;();</pre>
</blockquote>
<h2><a name="history">History</a></h2>
<p>November 2012. Glen Fernandes contributed implementations of
make_shared and allocate_shared for arrays.</p>
<hr>
<p>$Date: 2012-10-30 10:12:25 -0800 (Tue, 30 Oct 2012) $</p>
<p><small>Copyright 2012 Glen Fernandes. Distributed under the Boost

View File

@ -70,6 +70,11 @@
<td><a href="../../boost/make_shared.hpp">&lt;boost/make_shared.hpp&gt;</a></td>
<td>Efficient creation of <code>shared_ptr</code> objects.</td>
</tr>
<tr>
<td><a href="make_shared_array.html"><b>make_shared and allocate_shared for arrays</b></a></td>
<td><a href="../../boost/make_shared.hpp">&lt;boost/make_shared.hpp&gt;</a></td>
<td>Efficient creation of <code>shared_ptr</code> arrays.</td>
</tr>
</table>
</div>
<p>A test program, <a href="test/smart_ptr_test.cpp">smart_ptr_test.cpp</a>, is
@ -126,6 +131,12 @@
<p>Functions which destroy objects of the pointed to type are prohibited from
throwing exceptions by the <a href="#common_requirements">common requirements</a>.</p>
<h2><a name="History">History</a> and Acknowledgements</h2>
<p>November 2012. Glen Fernandes provided implementations of <b>make_shared</b>
and <b>allocate_shared</b> for arrays. They achieve a single allocation for an
array that can be initialized with constructor arguments or initializer lists
as well as overloads for default initialization and no value initialization.
See the <a href="make_shared_array.html">make_shared and allocate_shared for
arrays</a> page for more information.</p>
<p>January 2002. Peter Dimov reworked all four classes, adding features, fixing
bugs, and splitting them into four separate headers, and added <b>weak_ptr</b>.
See the <a href="compatibility.htm">compatibility</a> page for a summary of the