mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-07-31 05:07:21 +02:00
Derive empty base optimization from rebound allocator
This commit is contained in:
@ -28,6 +28,12 @@ namespace boost {
|
||||
size(size_ * array_total<T>::size) {
|
||||
}
|
||||
|
||||
template<class U>
|
||||
as_size_base(const as_size_base<T[], U>& other)
|
||||
: A(other),
|
||||
size(other.size) {
|
||||
}
|
||||
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
@ -38,6 +44,11 @@ namespace boost {
|
||||
: A(allocator) {
|
||||
}
|
||||
|
||||
template<class U>
|
||||
as_size_base(const as_size_base<T[N], U>& other)
|
||||
: A(other) {
|
||||
}
|
||||
|
||||
enum {
|
||||
size = array_total<T[N]>::size
|
||||
};
|
||||
@ -58,9 +69,13 @@ namespace boost {
|
||||
|
||||
template<class T, class R, class A, class Y = char>
|
||||
class as_allocator
|
||||
: as_size_base<T, A> {
|
||||
using as_size_base<T, A>::size;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
: as_size_base<T, typename std::allocator_traits<A>::
|
||||
template rebind_alloc<Y> > {
|
||||
#else
|
||||
: as_size_base<T, typename A::
|
||||
template rebind<Y>::other> {
|
||||
#endif
|
||||
template<class T_, class R_, class A_, class Y_>
|
||||
friend class as_allocator;
|
||||
|
||||
@ -78,6 +93,8 @@ namespace boost {
|
||||
typedef typename A::template rebind<char>::other CA;
|
||||
#endif
|
||||
|
||||
using as_size_base<T, YA>::size;
|
||||
|
||||
public:
|
||||
typedef typename array_base<T>::type type;
|
||||
|
||||
@ -105,36 +122,30 @@ namespace boost {
|
||||
};
|
||||
|
||||
as_allocator(const A& allocator, type** result)
|
||||
: as_size_base<T, A>(allocator),
|
||||
: as_size_base<T, YA>(allocator),
|
||||
data(result) {
|
||||
}
|
||||
|
||||
as_allocator(const A& allocator, std::size_t size_,
|
||||
type** result)
|
||||
: as_size_base<T, A>(allocator, size_),
|
||||
: as_size_base<T, YA>(allocator, size_),
|
||||
data(result) {
|
||||
}
|
||||
|
||||
template<class U>
|
||||
as_allocator(const as_allocator<T, R, A, U>& other)
|
||||
: as_size_base<T, A>(other),
|
||||
: as_size_base<T, YA>(other),
|
||||
data(other.data) {
|
||||
}
|
||||
|
||||
pointer address(reference value) const {
|
||||
YA ya(*this);
|
||||
return ya.address(value);
|
||||
}
|
||||
|
||||
const_pointer address(const_reference value) const {
|
||||
YA ya(*this);
|
||||
return ya.address(value);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
size_type max_size() const {
|
||||
YA ya(*this);
|
||||
return ya.max_size();
|
||||
return YT::max_size(*this);
|
||||
}
|
||||
#else
|
||||
using YA::address;
|
||||
using YA::max_size;
|
||||
#endif
|
||||
|
||||
pointer allocate(size_type count, const void* value = 0) {
|
||||
enum {
|
||||
@ -171,21 +182,19 @@ namespace boost {
|
||||
|
||||
template<class U>
|
||||
void construct(U* memory, const_reference value) {
|
||||
YA ya(*this);
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
YT::construct(ya, memory, value);
|
||||
YT::construct(*this, memory, value);
|
||||
#else
|
||||
ya.construct(memory, value);
|
||||
YA::construct(memory, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void destroy(U* memory) {
|
||||
YA ya(*this);
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
YT::destroy(ya, memory);
|
||||
YT::destroy(*this, memory);
|
||||
#else
|
||||
ya.destroy(memory);
|
||||
YA::destroy(memory);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -194,8 +203,7 @@ namespace boost {
|
||||
!defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
template<class U, class... Args>
|
||||
void construct(U* memory, Args&&... args) {
|
||||
YA ya(*this);
|
||||
YT::construct(ya, memory, std::forward<Args>(args)...);
|
||||
YT::construct(*this, memory, std::forward<Args>(args)...);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -223,8 +231,7 @@ namespace boost {
|
||||
private:
|
||||
void free(ms_init_tag) {
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
const A& a1(*this);
|
||||
as_destroy(a1, data.object, size);
|
||||
as_destroy(*this, data.object, size);
|
||||
#else
|
||||
ms_destroy(data.object, size);
|
||||
#endif
|
||||
@ -295,6 +302,7 @@ namespace boost {
|
||||
data(other.data) {
|
||||
}
|
||||
|
||||
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
pointer address(reference value) const {
|
||||
return &value;
|
||||
}
|
||||
@ -302,6 +310,7 @@ namespace boost {
|
||||
const_pointer address(const_reference value) const {
|
||||
return &value;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_type max_size() const {
|
||||
enum {
|
||||
|
@ -20,7 +20,7 @@ namespace boost {
|
||||
typedef ms_in_allocator_tag D;
|
||||
typedef sp_counted_impl_pda<P, D, A> Y;
|
||||
public:
|
||||
sp_counted_impl_pda(P, const D&, const A& allocator_)
|
||||
sp_counted_impl_pda(P, D, const A& allocator_)
|
||||
: allocator(allocator_) {
|
||||
}
|
||||
|
||||
|
@ -30,50 +30,50 @@
|
||||
user-supplied allocator, allowing finer control.</p>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
<pre>namespace boost {
|
||||
template<typename U> // U is T[]
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size);
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>();
|
||||
|
||||
template<typename U, typename A> // U is T[N]
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator);
|
||||
|
||||
template<typename U> // U is T[]
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size, const T& value);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, const T& value);
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(const T& value);
|
||||
|
||||
template<typename U, typename A> // U is T[N]
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, const T& value);
|
||||
|
||||
template<typename U> // U is T[]
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared_noinit</a>(size_t size);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared_noinit</a>(const A& allocator, size_t size);
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared_noinit</a>();
|
||||
|
||||
template<typename U, typename A> // U is T[N]
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared_noinit</a>(const A& allocator);
|
||||
}</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(<em>args</em>);
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, <em>args</em>);
|
||||
template<typename U>
|
||||
template<class U>
|
||||
shared_ptr<U> make_shared_noinit(<em>args</em>);
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, <em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> <code>U</code> is of the form <code>T[]</code> or
|
||||
@ -157,9 +157,9 @@ template<typename U, typename A>
|
||||
structures such as the reference counts.</p>
|
||||
</blockquote>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(size_t size);
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a value-initialized
|
||||
@ -172,9 +172,9 @@ template<typename U, typename A>
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared();
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a value-initialized
|
||||
@ -187,9 +187,9 @@ template<typename U, typename A>
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(size_t size, const T& value);
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to an object of type
|
||||
@ -203,9 +203,9 @@ template<typename U, typename A>
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size, {1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(const T& value);
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, const T& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to an object of type
|
||||
@ -219,9 +219,9 @@ template<typename U, typename A>
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>({1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared_noinit(size_t size);
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a default-initialized
|
||||
@ -234,9 +234,9 @@ template<typename U, typename A>
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared_noinit<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared_noinit();
|
||||
template<typename U, typename A>
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a default-initialized
|
||||
|
@ -18,30 +18,30 @@
|
||||
<code>unique_ptr</code> objects.</p>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
<pre>namespace boost {
|
||||
template<typename U> // U is not array
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>();
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<typename U, typename... Args> // U is not array
|
||||
template<class U, class... Args> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(Args&&... args);
|
||||
#endif
|
||||
|
||||
template<typename U> // U is not array
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(U&& value);
|
||||
|
||||
template<typename U> // U is T[]
|
||||
template<class U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(size_t size);
|
||||
|
||||
template<typename U> // U is not array
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>();
|
||||
|
||||
template<typename U> // U is T[]
|
||||
template<class U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>(size_t size);
|
||||
}</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(<em>args</em>);
|
||||
template<typename U>
|
||||
template<class U>
|
||||
unique_ptr<U> make_unique_noinit(<em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<p><b>Effects:</b> Allocates memory for an object of type <code>U</code>
|
||||
@ -73,7 +73,7 @@ template<typename U>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<typename U, typename... Args>
|
||||
<pre>template<class U, class... Args>
|
||||
unique_ptr<U> make_unique(Args&&... args);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to an object of type <code>U</code>,
|
||||
@ -86,7 +86,7 @@ unique_ptr<U> make_unique(Args&&... args);</pre>
|
||||
unique_ptr<point> p2 = boost::make_unique<point>(x, y);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(U&& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to an object of type <code>U</code>,
|
||||
@ -99,7 +99,7 @@ unique_ptr<U> make_unique(U&& value);</pre>
|
||||
unique_ptr<point> p2 = boost::make_unique<point>({-10, 25});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to a value-initialized object of type
|
||||
@ -112,7 +112,7 @@ unique_ptr<U> make_unique(size_t size);</pre>
|
||||
unique_ptr<int[][2]> p2 = boost::make_unique<int[][2]>(2);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique_noinit();</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to a default-initialized object of
|
||||
@ -125,7 +125,7 @@ unique_ptr<U> make_unique_noinit();</pre>
|
||||
unique_ptr<point> p2 = boost::make_unique_noinit<point>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique_noinit(size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to a default-initialized object of
|
||||
|
Reference in New Issue
Block a user