forked from boostorg/smart_ptr
Compare commits
35 Commits
feature/in
...
feature/de
Author | SHA1 | Date | |
---|---|---|---|
|
00f6b5dcb0 | ||
|
6195ae1eb0 | ||
|
30291c406a | ||
|
610f19f247 | ||
|
876d40a9ab | ||
|
e4d642c46a | ||
|
3dffa64f58 | ||
|
af92bd89ef | ||
|
4742143605 | ||
|
872bf10347 | ||
|
c0ae9b3728 | ||
|
1298c2e8e5 | ||
|
d593061b15 | ||
|
5072045f12 | ||
|
442e179920 | ||
|
9544a8cb91 | ||
|
5823d6bcc9 | ||
|
f56e609757 | ||
|
8df63a3d0e | ||
|
4b6cb1223b | ||
|
719e819570 | ||
|
a571b3a250 | ||
|
f17c5e8e3b | ||
|
e306b30dcf | ||
|
b6b49ef591 | ||
|
2122c7753c | ||
|
7c76fb385d | ||
|
372fac679b | ||
|
e3adcaed1e | ||
|
016e682af6 | ||
|
78e095d761 | ||
|
eb8a91cb46 | ||
|
513cd15378 | ||
|
7bfa6a1f3d | ||
|
8120bb44cb |
45
.travis.yml
45
.travis.yml
@@ -6,6 +6,8 @@ language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
dist: trusty
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
@@ -107,7 +109,7 @@ matrix:
|
||||
|
||||
- os: linux
|
||||
compiler: g++-8
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@@ -115,6 +117,36 @@ matrix:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-8
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-9
|
||||
env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-9
|
||||
env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-7
|
||||
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
|
||||
@@ -247,6 +279,17 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-7
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-8
|
||||
env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-8
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-7
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1
|
||||
|
@@ -20,7 +20,7 @@ environment:
|
||||
TOOLSET: msvc-12.0,msvc-14.0
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
TOOLSET: msvc-14.1,clang-win
|
||||
CXXSTD: 14,17
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
|
@@ -19,6 +19,8 @@ Greg Colvin, Beman Dawes, Peter Dimov, Glen Fernandes
|
||||
|
||||
include::smart_ptr/introduction.adoc[]
|
||||
|
||||
include::smart_ptr/changelog.adoc[]
|
||||
|
||||
include::smart_ptr/scoped_ptr.adoc[]
|
||||
|
||||
include::smart_ptr/scoped_array.adoc[]
|
||||
@@ -31,6 +33,8 @@ include::smart_ptr/make_shared.adoc[]
|
||||
|
||||
include::smart_ptr/enable_shared_from_this.adoc[]
|
||||
|
||||
include::smart_ptr/enable_shared_from.adoc[]
|
||||
|
||||
include::smart_ptr/make_unique.adoc[]
|
||||
|
||||
include::smart_ptr/intrusive_ptr.adoc[]
|
||||
|
25
doc/smart_ptr/changelog.adoc
Normal file
25
doc/smart_ptr/changelog.adoc
Normal file
@@ -0,0 +1,25 @@
|
||||
////
|
||||
Copyright 2019 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
|
||||
////
|
||||
|
||||
[#changelog]
|
||||
# Revision History
|
||||
:toc:
|
||||
:toc-title:
|
||||
:idprefix: changelog_
|
||||
|
||||
## Changes in 1.71.0
|
||||
|
||||
* Added aliasing constructors to `weak_ptr`
|
||||
* Added `weak_ptr<T>::empty()`
|
||||
* Added `enable_shared_from`, `shared_from`, and `weak_from`
|
||||
|
||||
## Changes in 1.65.0
|
||||
|
||||
* Added `atomic_shared_ptr`
|
||||
* Added `local_shared_ptr`, `make_local_shared`
|
89
doc/smart_ptr/enable_shared_from.adoc
Normal file
89
doc/smart_ptr/enable_shared_from.adoc
Normal file
@@ -0,0 +1,89 @@
|
||||
////
|
||||
Copyright 2002, 2003, 2015, 2017, 2019 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
|
||||
////
|
||||
|
||||
[#enable_shared_from]
|
||||
# enable_shared_from
|
||||
:toc:
|
||||
:toc-title:
|
||||
:idprefix: enable_shared_from_
|
||||
|
||||
## Description
|
||||
|
||||
`enable_shared_from` is used as a base class that allows a `shared_ptr` or a
|
||||
`weak_ptr` to be obtained given a raw pointer to the object, by using the
|
||||
functions `shared_from` and `weak_from`.
|
||||
|
||||
`enable_shared_from` differs from `enable_shared_from_this<T>` by the fact
|
||||
that it's not a template, and is its recommended replacement for new code.
|
||||
|
||||
## Example
|
||||
|
||||
```
|
||||
#include <boost/smart_ptr/enable_shared_from.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <cassert>
|
||||
|
||||
class Y: public boost::enable_shared_from
|
||||
{
|
||||
public:
|
||||
|
||||
boost::shared_ptr<Y> f()
|
||||
{
|
||||
return boost::shared_from( this );
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<Y> p(new Y);
|
||||
boost::shared_ptr<Y> q = p->f();
|
||||
assert(p == q);
|
||||
assert(!(p < q || q < p)); // p and q must share ownership
|
||||
}
|
||||
```
|
||||
|
||||
## Synopsis
|
||||
|
||||
`enable_shared_from` is defined in `<boost/smart_ptr/enable_shared_from.hpp>`.
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
|
||||
class enable_shared_from: public enable_shared_from_this<enable_shared_from>
|
||||
{
|
||||
};
|
||||
|
||||
template<class T> shared_ptr<T> shared_from( T * p );
|
||||
template<class T> weak_ptr<T> weak_from( T * p ) noexcept;
|
||||
}
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
```
|
||||
template<class T> shared_ptr<T> shared_from( T * p );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns:: `shared_ptr<T>( p\->enable_shared_from::shared_from_this(), p )`.
|
||||
|
||||
NOTE: Throws `bad_weak_ptr` when `p` is not owned by a `shared_ptr`.
|
||||
|
||||
```
|
||||
template<class T> weak_ptr<T> weak_from( T * p ) noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns:: `weak_ptr<T>( p\->enable_shared_from::weak_from_this(), p )`.
|
||||
|
||||
NOTE: Unlike `shared_from(this)`, `weak_from(this)` is valid in a destructor
|
||||
and returns a `weak_ptr` that is `expired()` but still shares ownership
|
||||
with other `weak_ptr` instances (if any) that refer to the object.
|
@@ -142,3 +142,7 @@ template<class T> weak_ptr<T const> weak_from_this() const noexcept;
|
||||
* {blank}
|
||||
+
|
||||
Returns:: `weak_this_`.
|
||||
|
||||
NOTE: Unlike `shared_from_this()`, `weak_from_this()` is valid in a destructor
|
||||
and returns a `weak_ptr` that is `expired()` but still shares ownership
|
||||
with other `weak_ptr` instances (if any) that refer to the object.
|
||||
|
@@ -11,7 +11,9 @@ http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
[#introduction]
|
||||
# Introduction
|
||||
:idprefix: intro
|
||||
:toc:
|
||||
:toc-title:
|
||||
:idprefix: intro_
|
||||
|
||||
Smart pointers are objects which store pointers to dynamically allocated (heap) objects.
|
||||
They behave much like built-in {cpp} pointers except that they automatically delete the object
|
||||
|
@@ -77,7 +77,7 @@ namespace boost {
|
||||
|
||||
explicit operator bool () const noexcept;
|
||||
|
||||
void swap(intrusive_ptr & b) noexept;
|
||||
void swap(intrusive_ptr & b) noexcept;
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
|
@@ -132,7 +132,6 @@ namespace boost {
|
||||
template<class Y> shared_ptr(shared_ptr<Y> && r) noexcept;
|
||||
|
||||
template<class Y> shared_ptr(shared_ptr<Y> const & r, element_type * p) noexcept;
|
||||
|
||||
template<class Y> shared_ptr(shared_ptr<Y> && r, element_type * p) noexcept;
|
||||
|
||||
template<class Y> explicit shared_ptr(weak_ptr<Y> const & r);
|
||||
@@ -373,7 +372,7 @@ template<class Y> shared_ptr(shared_ptr<Y> const & r, element_type * p) noexcept
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects:: constructs a `shared_ptr` that shares ownership with `r` and stores `p`.
|
||||
Effects:: Copy-constructs a `shared_ptr` from `r`, while storing `p` instead.
|
||||
|
||||
Postconditions:: `get() == p && use_count() == r.use_count()`.
|
||||
|
||||
|
@@ -88,6 +88,10 @@ namespace boost {
|
||||
|
||||
weak_ptr(weak_ptr && r) noexcept;
|
||||
|
||||
template<class Y> weak_ptr(shared_ptr<Y> const & r, element_type * p) noexcept;
|
||||
template<class Y> weak_ptr(weak_ptr<Y> const & r, element_type * p) noexcept;
|
||||
template<class Y> weak_ptr(weak_ptr<Y> && r, element_type * p) noexcept;
|
||||
|
||||
~weak_ptr() noexcept;
|
||||
|
||||
weak_ptr & operator=(weak_ptr const & r) noexcept;
|
||||
@@ -98,6 +102,8 @@ namespace boost {
|
||||
long use_count() const noexcept;
|
||||
bool expired() const noexcept;
|
||||
|
||||
bool empty() const noexcept;
|
||||
|
||||
shared_ptr<T> lock() const noexcept;
|
||||
|
||||
void reset() noexcept;
|
||||
@@ -157,6 +163,21 @@ weak_ptr(weak_ptr && r) noexcept;
|
||||
Effects:: Constructs a `weak_ptr` that has the value `r` held.
|
||||
Postconditions:: `r` is empty.
|
||||
|
||||
### aliasing constructors
|
||||
```
|
||||
template<class Y> weak_ptr(shared_ptr<Y> const & r, element_type * p) noexcept;
|
||||
```
|
||||
```
|
||||
template<class Y> weak_ptr(weak_ptr<Y> const & r, element_type * p) noexcept;
|
||||
```
|
||||
```
|
||||
template<class Y> weak_ptr(weak_ptr<Y> && r, element_type * p) noexcept;
|
||||
```
|
||||
Effects:: Constructs a `weak_ptr` from `r` as if by using the corresponding converting/copy/move constructor, but stores `p` instead.
|
||||
Postconditions:: `use_count() == r.use_count()`. When `!expired()`, `shared_ptr<T>(*this).get() == p`.
|
||||
|
||||
NOTE: These constructors are an extension, not present in `std::weak_ptr`.
|
||||
|
||||
### destructor
|
||||
```
|
||||
~weak_ptr() noexcept;
|
||||
@@ -204,6 +225,17 @@ bool expired() const noexcept;
|
||||
+
|
||||
Returns:: `use_count() == 0`.
|
||||
|
||||
### empty
|
||||
```
|
||||
bool empty() const noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns:: `true` when `*this` is empty, `false` otherwise.
|
||||
|
||||
NOTE: This function is an extension, not present in `std::weak_ptr`.
|
||||
|
||||
### lock
|
||||
```
|
||||
shared_ptr<T> lock() const noexcept;
|
||||
|
@@ -72,21 +72,19 @@ inline typename enable_if_<is_unbounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
allocate_local_shared(const A& allocator, std::size_t count)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::lsp_array_state<other> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
std::size_t size = count * detail::sp_array_count<type, scalar>::value;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size, start);
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count);
|
||||
detail::lsp_array_base& local = node->state().base();
|
||||
local.set(node);
|
||||
result.release();
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), &local);
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
|
||||
&local);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
@@ -94,23 +92,22 @@ inline typename enable_if_<is_bounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
allocate_local_shared(const A& allocator)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
enum {
|
||||
size = detail::sp_array_count<T, scalar>::value
|
||||
count = extent<T>::value
|
||||
};
|
||||
typedef detail::lsp_size_array_state<other, size> state;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::lsp_size_array_state<other, count> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size, start);
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count);
|
||||
detail::lsp_array_base& local = node->state().base();
|
||||
local.set(node);
|
||||
result.release();
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), &local);
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
|
||||
&local);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
@@ -119,25 +116,19 @@ inline typename enable_if_<is_unbounded_array<T>::value,
|
||||
allocate_local_shared(const A& allocator, std::size_t count,
|
||||
const typename remove_extent<T>::type& value)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::lsp_array_state<other> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
enum {
|
||||
total = detail::sp_array_count<type, scalar>::value
|
||||
};
|
||||
std::size_t size = count * total;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size,
|
||||
reinterpret_cast<const scalar*>(&value), total, start);
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count, value);
|
||||
detail::lsp_array_base& local = node->state().base();
|
||||
local.set(node);
|
||||
result.release();
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), &local);
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
|
||||
&local);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
@@ -146,25 +137,22 @@ inline typename enable_if_<is_bounded_array<T>::value,
|
||||
allocate_local_shared(const A& allocator,
|
||||
const typename remove_extent<T>::type& value)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
enum {
|
||||
size = detail::sp_array_count<T, scalar>::value
|
||||
count = extent<T>::value
|
||||
};
|
||||
typedef detail::lsp_size_array_state<other, size> state;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::lsp_size_array_state<other, count> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size,
|
||||
reinterpret_cast<const scalar*>(&value),
|
||||
detail::sp_array_count<type, scalar>::value, start);
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count, value);
|
||||
detail::lsp_array_base& local = node->state().base();
|
||||
local.set(node);
|
||||
result.release();
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), &local);
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
|
||||
&local);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
@@ -172,22 +160,8 @@ inline typename enable_if_<is_unbounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
allocate_local_shared_noinit(const A& allocator, std::size_t count)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
typedef detail::lsp_array_state<other> state;
|
||||
typedef detail::sp_array_base<state, false> base;
|
||||
std::size_t size = count * detail::sp_array_count<type, scalar>::value;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(detail::sp_default(), allocator,
|
||||
size, start);
|
||||
detail::lsp_array_base& local = node->state().base();
|
||||
local.set(node);
|
||||
result.release();
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), &local);
|
||||
return boost::allocate_local_shared<T>(boost::noinit_adapt(allocator),
|
||||
count);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
@@ -195,24 +169,7 @@ inline typename enable_if_<is_bounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
allocate_local_shared_noinit(const A& allocator)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
enum {
|
||||
size = detail::sp_array_count<T, scalar>::value
|
||||
};
|
||||
typedef detail::lsp_size_array_state<other, size> state;
|
||||
typedef detail::sp_array_base<state, false> base;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(detail::sp_default(), allocator,
|
||||
size, start);
|
||||
detail::lsp_array_base& local = node->state().base();
|
||||
local.set(node);
|
||||
result.release();
|
||||
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), &local);
|
||||
return boost::allocate_local_shared<T>(boost::noinit_adapt(allocator));
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
@@ -8,15 +8,14 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#ifndef BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
|
||||
|
||||
#include <boost/core/alloc_construct.hpp>
|
||||
#include <boost/core/first_scalar.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
#include <boost/type_traits/enable_if.hpp>
|
||||
#include <boost/type_traits/extent.hpp>
|
||||
#include <boost/type_traits/is_bounded_array.hpp>
|
||||
#include <boost/type_traits/is_unbounded_array.hpp>
|
||||
#include <boost/type_traits/has_trivial_assign.hpp>
|
||||
#include <boost/type_traits/has_trivial_constructor.hpp>
|
||||
#include <boost/type_traits/has_trivial_destructor.hpp>
|
||||
#include <boost/type_traits/remove_all_extents.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/type_traits/remove_extent.hpp>
|
||||
#include <boost/type_traits/type_with_alignment.hpp>
|
||||
@@ -25,15 +24,22 @@ namespace boost {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct sp_array_scalar {
|
||||
struct sp_array_element {
|
||||
typedef typename boost::remove_cv<typename
|
||||
boost::remove_all_extents<T>::type>::type type;
|
||||
boost::remove_extent<T>::type>::type type;
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
template<class T>
|
||||
struct sp_array_count {
|
||||
enum {
|
||||
value = sizeof(T) / sizeof(U)
|
||||
value = 1
|
||||
};
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct sp_array_count<T[N]> {
|
||||
enum {
|
||||
value = N * sp_array_count<T>::value
|
||||
};
|
||||
};
|
||||
|
||||
@@ -70,154 +76,6 @@ sp_objects(std::size_t size) BOOST_SP_NOEXCEPT
|
||||
return (size + sizeof(T) - 1) / sizeof(T);
|
||||
}
|
||||
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<!E &&
|
||||
boost::has_trivial_destructor<T>::value>::type
|
||||
sp_array_destroy(A&, T*, std::size_t) BOOST_SP_NOEXCEPT { }
|
||||
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<!E &&
|
||||
!boost::has_trivial_destructor<T>::value>::type
|
||||
sp_array_destroy(A&, T* ptr, std::size_t size)
|
||||
{
|
||||
while (size > 0) {
|
||||
ptr[--size].~T();
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<E>::type
|
||||
sp_array_destroy(A& allocator, T* ptr, std::size_t size)
|
||||
{
|
||||
while (size > 0) {
|
||||
std::allocator_traits<A>::destroy(allocator, ptr + --size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template<bool E, class A, class T>
|
||||
class sp_destroyer {
|
||||
public:
|
||||
sp_destroyer(A& allocator, T* ptr) BOOST_SP_NOEXCEPT
|
||||
: allocator_(allocator),
|
||||
ptr_(ptr),
|
||||
size_(0) { }
|
||||
|
||||
~sp_destroyer() {
|
||||
sp_array_destroy<E>(allocator_, ptr_, size_);
|
||||
}
|
||||
|
||||
std::size_t& size() BOOST_SP_NOEXCEPT {
|
||||
return size_;
|
||||
}
|
||||
|
||||
private:
|
||||
sp_destroyer(const sp_destroyer&);
|
||||
sp_destroyer& operator=(const sp_destroyer&);
|
||||
|
||||
A& allocator_;
|
||||
T* ptr_;
|
||||
std::size_t size_;
|
||||
};
|
||||
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<!E &&
|
||||
boost::has_trivial_constructor<T>::value &&
|
||||
boost::has_trivial_assign<T>::value &&
|
||||
boost::has_trivial_destructor<T>::value>::type
|
||||
sp_array_construct(A&, T* ptr, std::size_t size)
|
||||
{
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
ptr[i] = T();
|
||||
}
|
||||
}
|
||||
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<!E &&
|
||||
boost::has_trivial_constructor<T>::value &&
|
||||
boost::has_trivial_assign<T>::value &&
|
||||
boost::has_trivial_destructor<T>::value>::type
|
||||
sp_array_construct(A&, T* ptr, std::size_t size, const T* list,
|
||||
std::size_t count)
|
||||
{
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
ptr[i] = list[i % count];
|
||||
}
|
||||
}
|
||||
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<!E &&
|
||||
!(boost::has_trivial_constructor<T>::value &&
|
||||
boost::has_trivial_assign<T>::value &&
|
||||
boost::has_trivial_destructor<T>::value)>::type
|
||||
sp_array_construct(A& none, T* ptr, std::size_t size)
|
||||
{
|
||||
sp_destroyer<E, A, T> hold(none, ptr);
|
||||
for (std::size_t& i = hold.size(); i < size; ++i) {
|
||||
::new(static_cast<void*>(ptr + i)) T();
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<!E &&
|
||||
!(boost::has_trivial_constructor<T>::value &&
|
||||
boost::has_trivial_assign<T>::value &&
|
||||
boost::has_trivial_destructor<T>::value)>::type
|
||||
sp_array_construct(A& none, T* ptr, std::size_t size, const T* list,
|
||||
std::size_t count)
|
||||
{
|
||||
sp_destroyer<E, A, T> hold(none, ptr);
|
||||
for (std::size_t& i = hold.size(); i < size; ++i) {
|
||||
::new(static_cast<void*>(ptr + i)) T(list[i % count]);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<E>::type
|
||||
sp_array_construct(A& allocator, T* ptr, std::size_t size)
|
||||
{
|
||||
sp_destroyer<E, A, T> hold(allocator, ptr);
|
||||
for (std::size_t& i = hold.size(); i < size; ++i) {
|
||||
std::allocator_traits<A>::construct(allocator, ptr + i);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<bool E, class A, class T>
|
||||
inline typename boost::enable_if_<E>::type
|
||||
sp_array_construct(A& allocator, T* ptr, std::size_t size, const T* list,
|
||||
std::size_t count)
|
||||
{
|
||||
sp_destroyer<E, A, T> hold(allocator, ptr);
|
||||
for (std::size_t& i = hold.size(); i < size; ++i) {
|
||||
std::allocator_traits<A>::construct(allocator, ptr + i,
|
||||
list[i % count]);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class A, class T>
|
||||
inline typename
|
||||
boost::enable_if_<boost::has_trivial_constructor<T>::value>::type
|
||||
sp_array_default(A&, T*, std::size_t) BOOST_SP_NOEXCEPT { }
|
||||
|
||||
template<class A, class T>
|
||||
inline typename
|
||||
boost::enable_if_<!boost::has_trivial_constructor<T>::value>::type
|
||||
sp_array_default(A& none, T* ptr, std::size_t size)
|
||||
{
|
||||
sp_destroyer<false, A, T> hold(none, ptr);
|
||||
for (std::size_t& i = hold.size(); i < size; ++i) {
|
||||
::new(static_cast<void*>(ptr + i)) T;
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<class A>
|
||||
class sp_array_state {
|
||||
public:
|
||||
@@ -262,29 +120,6 @@ private:
|
||||
A allocator_;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class A>
|
||||
struct sp_use_construct {
|
||||
enum {
|
||||
value = true
|
||||
};
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct sp_use_construct<std::allocator<T> > {
|
||||
enum {
|
||||
value = false
|
||||
};
|
||||
};
|
||||
#else
|
||||
template<class>
|
||||
struct sp_use_construct {
|
||||
enum {
|
||||
value = false
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
template<class T, class U>
|
||||
struct sp_array_alignment {
|
||||
enum {
|
||||
@@ -300,39 +135,32 @@ struct sp_array_offset {
|
||||
};
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
struct sp_array_storage {
|
||||
enum {
|
||||
value = sp_array_alignment<T, U>::value
|
||||
};
|
||||
typedef typename boost::type_with_alignment<value>::type type;
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
template<class U, class T>
|
||||
inline U*
|
||||
sp_array_start(void* base) BOOST_SP_NOEXCEPT
|
||||
sp_array_start(T* base) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
enum {
|
||||
size = sp_array_offset<T, U>::value
|
||||
};
|
||||
return reinterpret_cast<U*>(static_cast<char*>(base) + size);
|
||||
return reinterpret_cast<U*>(reinterpret_cast<char*>(base) + size);
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
class sp_array_creator {
|
||||
typedef typename A::value_type scalar;
|
||||
typedef typename A::value_type element;
|
||||
|
||||
enum {
|
||||
offset = sp_array_offset<T, scalar>::value
|
||||
offset = sp_array_offset<T, element>::value
|
||||
};
|
||||
|
||||
typedef typename sp_array_storage<T, scalar>::type type;
|
||||
typedef typename boost::type_with_alignment<sp_array_alignment<T,
|
||||
element>::value>::type type;
|
||||
|
||||
public:
|
||||
template<class U>
|
||||
sp_array_creator(const U& other, std::size_t size) BOOST_SP_NOEXCEPT
|
||||
: other_(other),
|
||||
size_(sp_objects<type>(offset + sizeof(scalar) * size)) { }
|
||||
size_(sp_objects<type>(offset + sizeof(element) * size)) { }
|
||||
|
||||
T* create() {
|
||||
return reinterpret_cast<T*>(other_.allocate(size_));
|
||||
@@ -347,9 +175,7 @@ private:
|
||||
std::size_t size_;
|
||||
};
|
||||
|
||||
struct sp_default { };
|
||||
|
||||
template<class T, bool E = sp_use_construct<T>::value>
|
||||
template<class T>
|
||||
class BOOST_SYMBOL_VISIBLE sp_array_base
|
||||
: public sp_counted_base {
|
||||
typedef typename T::type allocator;
|
||||
@@ -358,23 +184,22 @@ public:
|
||||
typedef typename allocator::value_type type;
|
||||
|
||||
template<class A>
|
||||
sp_array_base(const A& other, std::size_t size, type* start)
|
||||
sp_array_base(const A& other, type* start, std::size_t size)
|
||||
: state_(other, size) {
|
||||
sp_array_construct<E>(state_.allocator(), start, state_.size());
|
||||
boost::alloc_construct_n(state_.allocator(),
|
||||
boost::first_scalar(start),
|
||||
state_.size() * sp_array_count<type>::value);
|
||||
}
|
||||
|
||||
template<class A>
|
||||
sp_array_base(const A& other, std::size_t size, const type* list,
|
||||
std::size_t count, type* start)
|
||||
template<class A, class U>
|
||||
sp_array_base(const A& other, type* start, std::size_t size, const U& list)
|
||||
: state_(other, size) {
|
||||
sp_array_construct<E>(state_.allocator(), start, state_.size(), list,
|
||||
count);
|
||||
}
|
||||
|
||||
template<class A>
|
||||
sp_array_base(sp_default, const A& other, std::size_t size, type* start)
|
||||
: state_(other, size) {
|
||||
sp_array_default(state_.allocator(), start, state_.size());
|
||||
enum {
|
||||
count = sp_array_count<type>::value
|
||||
};
|
||||
boost::alloc_construct_n(state_.allocator(),
|
||||
boost::first_scalar(start), state_.size() * count,
|
||||
boost::first_scalar(&list), count);
|
||||
}
|
||||
|
||||
T& state() BOOST_SP_NOEXCEPT {
|
||||
@@ -382,8 +207,9 @@ public:
|
||||
}
|
||||
|
||||
virtual void dispose() BOOST_SP_NOEXCEPT {
|
||||
sp_array_destroy<E>(state_.allocator(),
|
||||
sp_array_start<sp_array_base, type>(this), state_.size());
|
||||
boost::alloc_destroy_n(state_.allocator(),
|
||||
boost::first_scalar(sp_array_start<type>(this)),
|
||||
state_.size() * sp_array_count<type>::value);
|
||||
}
|
||||
|
||||
virtual void destroy() BOOST_SP_NOEXCEPT {
|
||||
@@ -393,11 +219,11 @@ public:
|
||||
other.destroy(this);
|
||||
}
|
||||
|
||||
virtual void* get_deleter(const sp_typeinfo&) BOOST_SP_NOEXCEPT {
|
||||
virtual void* get_deleter(const sp_typeinfo_&) BOOST_SP_NOEXCEPT {
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void* get_local_deleter(const sp_typeinfo&) BOOST_SP_NOEXCEPT {
|
||||
virtual void* get_local_deleter(const sp_typeinfo_&) BOOST_SP_NOEXCEPT {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -423,11 +249,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
T* get() const {
|
||||
T* get() const BOOST_SP_NOEXCEPT {
|
||||
return result_;
|
||||
}
|
||||
|
||||
void release() {
|
||||
void release() BOOST_SP_NOEXCEPT {
|
||||
result_ = 0;
|
||||
}
|
||||
|
||||
@@ -445,40 +271,37 @@ template<class T, class A>
|
||||
inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
|
||||
allocate_shared(const A& allocator, std::size_t count)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::sp_array_state<other> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
std::size_t size = count * detail::sp_array_count<type, scalar>::value;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_counted_base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size, start);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count);
|
||||
result.release();
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), detail::shared_count(node));
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(), start,
|
||||
detail::shared_count(static_cast<detail::sp_counted_base*>(node)));
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
|
||||
allocate_shared(const A& allocator)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
enum {
|
||||
size = detail::sp_array_count<T, scalar>::value
|
||||
count = extent<T>::value
|
||||
};
|
||||
typedef detail::sp_size_array_state<other, size> state;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::sp_size_array_state<other, extent<T>::value> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_counted_base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size, start);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count);
|
||||
result.release();
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), detail::shared_count(node));
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(), start,
|
||||
detail::shared_count(static_cast<detail::sp_counted_base*>(node)));
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
@@ -486,23 +309,17 @@ inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
|
||||
allocate_shared(const A& allocator, std::size_t count,
|
||||
const typename remove_extent<T>::type& value)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::sp_array_state<other> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
enum {
|
||||
total = detail::sp_array_count<type, scalar>::value
|
||||
};
|
||||
std::size_t size = count * total;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_counted_base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size,
|
||||
reinterpret_cast<const scalar*>(&value), total, start);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count, value);
|
||||
result.release();
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), detail::shared_count(node));
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(), start,
|
||||
detail::shared_count(static_cast<detail::sp_counted_base*>(node)));
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
@@ -510,65 +327,34 @@ inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
|
||||
allocate_shared(const A& allocator,
|
||||
const typename remove_extent<T>::type& value)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
enum {
|
||||
size = detail::sp_array_count<T, scalar>::value
|
||||
count = extent<T>::value
|
||||
};
|
||||
typedef detail::sp_size_array_state<other, size> state;
|
||||
typedef typename detail::sp_array_element<T>::type element;
|
||||
typedef typename detail::sp_bind_allocator<A, element>::type other;
|
||||
typedef detail::sp_size_array_state<other, extent<T>::value> state;
|
||||
typedef detail::sp_array_base<state> base;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_counted_base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, size,
|
||||
reinterpret_cast<const scalar*>(&value),
|
||||
detail::sp_array_count<type, scalar>::value, start);
|
||||
detail::sp_array_result<other, base> result(allocator, count);
|
||||
base* node = result.get();
|
||||
element* start = detail::sp_array_start<element>(node);
|
||||
::new(static_cast<void*>(node)) base(allocator, start, count, value);
|
||||
result.release();
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), detail::shared_count(node));
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(), start,
|
||||
detail::shared_count(static_cast<detail::sp_counted_base*>(node)));
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
|
||||
allocate_shared_noinit(const A& allocator, std::size_t count)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
typedef detail::sp_array_state<other> state;
|
||||
typedef detail::sp_array_base<state, false> base;
|
||||
std::size_t size = count * detail::sp_array_count<type, scalar>::value;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_counted_base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(detail::sp_default(), allocator,
|
||||
size, start);
|
||||
result.release();
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), detail::shared_count(node));
|
||||
return boost::allocate_shared<T>(boost::noinit_adapt(allocator), count);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
|
||||
allocate_shared_noinit(const A& allocator)
|
||||
{
|
||||
typedef typename remove_extent<T>::type type;
|
||||
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||
enum {
|
||||
size = detail::sp_array_count<T, scalar>::value
|
||||
};
|
||||
typedef detail::sp_size_array_state<other, size> state;
|
||||
typedef detail::sp_array_base<state, false> base;
|
||||
detail::sp_array_result<other, base> result(allocator, size);
|
||||
detail::sp_counted_base* node = result.get();
|
||||
scalar* start = detail::sp_array_start<base, scalar>(node);
|
||||
::new(static_cast<void*>(node)) base(detail::sp_default(), allocator,
|
||||
size, start);
|
||||
result.release();
|
||||
return shared_ptr<T>(detail::sp_internal_constructor_tag(),
|
||||
reinterpret_cast<type*>(start), detail::shared_count(node));
|
||||
return boost::allocate_shared<T>(boost::noinit_adapt(allocator));
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
@@ -63,6 +63,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
atomic_shared_ptr( shared_ptr<T> p ) BOOST_SP_NOEXCEPT
|
||||
: p_( std::move( p ) ), l_ BOOST_DETAIL_SPINLOCK_INIT
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
atomic_shared_ptr() BOOST_SP_NOEXCEPT
|
||||
@@ -71,8 +76,6 @@ public:
|
||||
std::memcpy( &l_, &init, sizeof( init ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
atomic_shared_ptr( shared_ptr<T> p ) BOOST_SP_NOEXCEPT
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
: p_( std::move( p ) )
|
||||
@@ -84,6 +87,8 @@ public:
|
||||
std::memcpy( &l_, &init, sizeof( init ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
atomic_shared_ptr& operator=( shared_ptr<T> r ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
boost::detail::spinlock::scoped_lock lock( l_ );
|
||||
|
@@ -26,7 +26,7 @@ class atomic_count
|
||||
{
|
||||
public:
|
||||
|
||||
explicit atomic_count( long v ): value_( v )
|
||||
explicit atomic_count( long v ): value_( static_cast< std::int_least32_t >( v ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -499,12 +499,12 @@ public:
|
||||
return std::less<sp_counted_base *>()( a.pi_, b.pi_ );
|
||||
}
|
||||
|
||||
void * get_deleter( sp_typeinfo const & ti ) const BOOST_SP_NOEXCEPT
|
||||
void * get_deleter( sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return pi_? pi_->get_deleter( ti ): 0;
|
||||
}
|
||||
|
||||
void * get_local_deleter( sp_typeinfo const & ti ) const BOOST_SP_NOEXCEPT
|
||||
void * get_local_deleter( sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return pi_? pi_->get_local_deleter( ti ): 0;
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
// Lock-free algorithm by Alexander Terekhov
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <machine/sys/inline.h>
|
||||
|
||||
@@ -104,8 +104,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -20,7 +20,7 @@
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <builtins.h>
|
||||
#include <sys/atomic_op.h>
|
||||
@@ -96,8 +96,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -15,7 +15,7 @@
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
@@ -99,8 +99,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT = 0;
|
||||
|
||||
void add_ref_copy() BOOST_SP_NOEXCEPT
|
||||
|
@@ -24,7 +24,7 @@
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -124,8 +124,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -25,7 +25,7 @@
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -112,8 +112,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -16,7 +16,7 @@
|
||||
// Lock-free algorithm by Alexander Terekhov
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -111,8 +111,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -20,7 +20,7 @@
|
||||
// Lock-free algorithm by Alexander Terekhov
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -141,8 +141,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -24,7 +24,7 @@
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -135,8 +135,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -19,7 +19,7 @@
|
||||
//
|
||||
// Thanks to Michael van der Westhuizen
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <inttypes.h> // int32_t
|
||||
|
||||
@@ -120,8 +120,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -24,7 +24,7 @@
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -127,8 +127,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -18,7 +18,7 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
@@ -61,8 +61,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT = 0;
|
||||
|
||||
void add_ref_copy() BOOST_SP_NOEXCEPT
|
||||
|
@@ -18,7 +18,7 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
@@ -72,8 +72,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -19,7 +19,7 @@
|
||||
//
|
||||
// Thanks to Michael van der Westhuizen
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <inttypes.h> // uint32_t
|
||||
|
||||
@@ -115,8 +115,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -20,7 +20,7 @@
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <atomic.h>
|
||||
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -18,7 +18,7 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
@@ -84,8 +84,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -15,7 +15,7 @@
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <atomic>
|
||||
@@ -91,8 +91,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
|
||||
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT = 0;
|
||||
|
||||
void add_ref_copy() BOOST_SP_NOEXCEPT
|
||||
|
@@ -15,7 +15,7 @@
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <limits.h>
|
||||
|
||||
@@ -109,8 +109,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -21,7 +21,7 @@
|
||||
// formulation
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
extern "builtin" void __lwsync(void);
|
||||
@@ -104,8 +104,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -25,8 +25,8 @@
|
||||
//
|
||||
|
||||
#include <boost/smart_ptr/detail/sp_interlocked.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -67,8 +67,8 @@ public:
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
|
@@ -93,12 +93,12 @@ public:
|
||||
boost::checked_delete( px_ );
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ) BOOST_SP_NOEXCEPT
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ) BOOST_SP_NOEXCEPT
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -173,14 +173,14 @@ public:
|
||||
del( ptr );
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return ti == BOOST_SP_TYPEID(D)? &reinterpret_cast<char&>( del ): 0;
|
||||
return ti == BOOST_SP_TYPEID_(D)? &reinterpret_cast<char&>( del ): 0;
|
||||
}
|
||||
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return ti == BOOST_SP_TYPEID(D)? boost::detail::get_local_deleter( boost::addressof( del ) ): 0;
|
||||
return ti == BOOST_SP_TYPEID_(D)? boost::detail::get_local_deleter( boost::addressof( del ) ): 0;
|
||||
}
|
||||
|
||||
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT
|
||||
@@ -266,14 +266,14 @@ public:
|
||||
a2.deallocate( this, 1 );
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT
|
||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return ti == BOOST_SP_TYPEID( D )? &reinterpret_cast<char&>( d_ ): 0;
|
||||
return ti == BOOST_SP_TYPEID_( D )? &reinterpret_cast<char&>( d_ ): 0;
|
||||
}
|
||||
|
||||
virtual void * get_local_deleter( sp_typeinfo const & ti ) BOOST_SP_NOEXCEPT
|
||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return ti == BOOST_SP_TYPEID(D)? boost::detail::get_local_deleter( boost::addressof( d_ ) ): 0;
|
||||
return ti == BOOST_SP_TYPEID_( D )? boost::detail::get_local_deleter( boost::addressof( d_ ) ): 0;
|
||||
}
|
||||
|
||||
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT
|
||||
|
58
include/boost/smart_ptr/detail/sp_typeinfo_.hpp
Normal file
58
include/boost/smart_ptr/detail/sp_typeinfo_.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_SP_TYPEINFO_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_DETAIL_SP_TYPEINFO_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// smart_ptr/detail/sp_typeinfo_.hpp
|
||||
//
|
||||
// Copyright 2007, 2019 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>
|
||||
|
||||
#if defined( BOOST_NO_TYPEID ) || defined( BOOST_NO_STD_TYPEINFO )
|
||||
|
||||
#include <boost/core/typeinfo.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef boost::core::typeinfo sp_typeinfo_;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#define BOOST_SP_TYPEID_(T) BOOST_CORE_TYPEID(T)
|
||||
|
||||
#else // defined( BOOST_NO_TYPEID ) || defined( BOOST_NO_STD_TYPEINFO )
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef std::type_info sp_typeinfo_;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#define BOOST_SP_TYPEID_(T) typeid(T)
|
||||
|
||||
#endif // defined( BOOST_NO_TYPEID ) || defined( BOOST_NO_STD_TYPEINFO )
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_TYPEINFO_HPP_INCLUDED
|
37
include/boost/smart_ptr/enable_shared_from.hpp
Normal file
37
include/boost/smart_ptr/enable_shared_from.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_ENABLE_SHARED_FROM_HPP_INCLUDED
|
||||
|
||||
// enable_shared_from.hpp
|
||||
//
|
||||
// Copyright 2019 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
|
||||
//
|
||||
// See http://www.boost.org/libs/smart_ptr/ for documentation.
|
||||
|
||||
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
class enable_shared_from: public enable_shared_from_this<enable_shared_from>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template<class T> shared_ptr<T> shared_from( T * p )
|
||||
{
|
||||
return shared_ptr<T>( p->enable_shared_from::shared_from_this(), p );
|
||||
}
|
||||
|
||||
template<class T> weak_ptr<T> weak_from( T * p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return weak_ptr<T>( p->enable_shared_from::weak_from_this(), p );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_HPP_INCLUDED
|
@@ -144,8 +144,7 @@ template<typename T>
|
||||
boost::weak_ptr<T> weak_from_raw(T *p)
|
||||
{
|
||||
BOOST_ASSERT(p != 0);
|
||||
boost::weak_ptr<T> result;
|
||||
result._internal_aliasing_assign(p->enable_shared_from_raw::weak_from_this(), p);
|
||||
boost::weak_ptr<T> result(p->enable_shared_from_raw::weak_from_this(), p);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -297,6 +297,8 @@ template<class T> T * get_pointer(intrusive_ptr<T> const & p) BOOST_SP_NOEXCEPT
|
||||
return p.get();
|
||||
}
|
||||
|
||||
// pointer casts
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
|
||||
{
|
||||
return static_cast<T *>(p.get());
|
||||
@@ -312,6 +314,31 @@ template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U
|
||||
return dynamic_cast<T *>(p.get());
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> static_pointer_cast( intrusive_ptr<U> && p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return intrusive_ptr<T>( static_cast<T*>( p.detach() ), false );
|
||||
}
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> const_pointer_cast( intrusive_ptr<U> && p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return intrusive_ptr<T>( const_cast<T*>( p.detach() ), false );
|
||||
}
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast( intrusive_ptr<U> && p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
T * p2 = dynamic_cast<T*>( p.get() );
|
||||
|
||||
intrusive_ptr<T> r( p2, false );
|
||||
|
||||
if( p2 ) p.detach();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif // defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
// operator<<
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM)
|
||||
|
@@ -9,6 +9,7 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#ifndef BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP
|
||||
|
||||
#include <boost/core/default_allocator.hpp>
|
||||
#include <boost/smart_ptr/allocate_local_shared_array.hpp>
|
||||
|
||||
namespace boost {
|
||||
@@ -18,8 +19,8 @@ inline typename enable_if_<is_bounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
make_local_shared()
|
||||
{
|
||||
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>());
|
||||
return boost::allocate_local_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -27,8 +28,8 @@ inline typename enable_if_<is_bounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
make_local_shared(const typename remove_extent<T>::type& value)
|
||||
{
|
||||
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), value);
|
||||
return boost::allocate_local_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>(), value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -36,8 +37,8 @@ inline typename enable_if_<is_unbounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
make_local_shared(std::size_t size)
|
||||
{
|
||||
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size);
|
||||
return boost::allocate_local_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>(), size);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -46,8 +47,8 @@ inline typename enable_if_<is_unbounded_array<T>::value,
|
||||
make_local_shared(std::size_t size,
|
||||
const typename remove_extent<T>::type& value)
|
||||
{
|
||||
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size, value);
|
||||
return boost::allocate_local_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>(), size, value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -55,8 +56,8 @@ inline typename enable_if_<is_bounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
make_local_shared_noinit()
|
||||
{
|
||||
return boost::allocate_local_shared_noinit<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>());
|
||||
return boost::allocate_local_shared_noinit<T>(boost::
|
||||
default_allocator<typename detail::sp_array_element<T>::type>());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -64,8 +65,8 @@ inline typename enable_if_<is_unbounded_array<T>::value,
|
||||
local_shared_ptr<T> >::type
|
||||
make_local_shared_noinit(std::size_t size)
|
||||
{
|
||||
return boost::allocate_local_shared_noinit<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size);
|
||||
return boost::allocate_local_shared_noinit<T>(boost::
|
||||
default_allocator<typename detail::sp_array_element<T>::type>(), size);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
@@ -8,6 +8,7 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#ifndef BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
|
||||
|
||||
#include <boost/core/default_allocator.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
namespace boost {
|
||||
@@ -16,48 +17,48 @@ template<class T>
|
||||
inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
|
||||
make_shared()
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>());
|
||||
return boost::allocate_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
|
||||
make_shared(const typename remove_extent<T>::type& value)
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), value);
|
||||
return boost::allocate_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>(), value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
|
||||
make_shared(std::size_t size)
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size);
|
||||
return boost::allocate_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>(), size);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
|
||||
make_shared(std::size_t size, const typename remove_extent<T>::type& value)
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size, value);
|
||||
return boost::allocate_shared<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>(), size, value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename enable_if_<is_bounded_array<T>::value, shared_ptr<T> >::type
|
||||
make_shared_noinit()
|
||||
{
|
||||
return boost::allocate_shared_noinit<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>());
|
||||
return boost::allocate_shared_noinit<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
|
||||
make_shared_noinit(std::size_t size)
|
||||
{
|
||||
return boost::allocate_shared_noinit<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size);
|
||||
return boost::allocate_shared_noinit<T>(boost::default_allocator<typename
|
||||
detail::sp_array_element<T>::type>(), size);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
@@ -225,7 +225,7 @@ public:
|
||||
pn.swap(other.pn);
|
||||
}
|
||||
|
||||
void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const BOOST_SP_NOEXCEPT
|
||||
void * _internal_get_deleter( boost::detail::sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return pn.get_deleter( ti );
|
||||
}
|
||||
@@ -285,7 +285,7 @@ template<class T> void swap(shared_array<T> & a, shared_array<T> & b) BOOST_SP_N
|
||||
|
||||
template< class D, class T > D * get_deleter( shared_array<T> const & p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return static_cast< D * >( p._internal_get_deleter( BOOST_SP_TYPEID(D) ) );
|
||||
return static_cast< D * >( p._internal_get_deleter( BOOST_SP_TYPEID_(D) ) );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
@@ -777,12 +777,12 @@ public:
|
||||
return pn < rhs.pn;
|
||||
}
|
||||
|
||||
void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const BOOST_SP_NOEXCEPT
|
||||
void * _internal_get_deleter( boost::detail::sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return pn.get_deleter( ti );
|
||||
}
|
||||
|
||||
void * _internal_get_local_deleter( boost::detail::sp_typeinfo const & ti ) const BOOST_SP_NOEXCEPT
|
||||
void * _internal_get_local_deleter( boost::detail::sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return pn.get_local_deleter( ti );
|
||||
}
|
||||
@@ -1008,7 +1008,7 @@ namespace detail
|
||||
|
||||
template<class D, class T> D * basic_get_deleter( shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID(D)) );
|
||||
return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID_(D)) );
|
||||
}
|
||||
|
||||
template<class D, class T> D * basic_get_local_deleter( D *, shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT;
|
||||
@@ -1165,12 +1165,12 @@ namespace detail
|
||||
|
||||
template<class D, class T> D * basic_get_local_deleter( D *, shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID(local_sp_deleter<D>) ) );
|
||||
return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID_(local_sp_deleter<D>) ) );
|
||||
}
|
||||
|
||||
template<class D, class T> D const * basic_get_local_deleter( D const *, shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID(local_sp_deleter<D>) ) );
|
||||
return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID_(local_sp_deleter<D>) ) );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
@@ -137,6 +137,23 @@ public:
|
||||
boost::detail::sp_assert_convertible< Y, T >();
|
||||
}
|
||||
|
||||
// aliasing
|
||||
template<class Y> weak_ptr(shared_ptr<Y> const & r, element_type * p) BOOST_SP_NOEXCEPT: px( p ), pn( r.pn )
|
||||
{
|
||||
}
|
||||
|
||||
template<class Y> weak_ptr(weak_ptr<Y> const & r, element_type * p) BOOST_SP_NOEXCEPT: px( p ), pn( r.pn )
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class Y> weak_ptr(weak_ptr<Y> && r, element_type * p) BOOST_SP_NOEXCEPT: px( p ), pn( std::move( r.pn ) )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
|
||||
|
||||
template<class Y>
|
||||
@@ -194,6 +211,11 @@ public:
|
||||
return pn.empty();
|
||||
}
|
||||
|
||||
bool empty() const BOOST_SP_NOEXCEPT // extension, not in std::weak_ptr
|
||||
{
|
||||
return pn.empty();
|
||||
}
|
||||
|
||||
void reset() BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type().swap(*this);
|
||||
@@ -205,13 +227,6 @@ public:
|
||||
pn.swap(other.pn);
|
||||
}
|
||||
|
||||
template<typename Y>
|
||||
void _internal_aliasing_assign(weak_ptr<Y> const & r, element_type * px2) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
px = px2;
|
||||
pn = r.pn;
|
||||
}
|
||||
|
||||
template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return pn < rhs.pn;
|
||||
|
35
test/Jamfile
35
test/Jamfile
@@ -158,18 +158,18 @@ compile-fail array_fail_dereference.cpp ;
|
||||
compile-fail array_fail_member_access.cpp ;
|
||||
compile-fail array_fail_array_access.cpp ;
|
||||
|
||||
run make_shared_array_test.cpp ;
|
||||
run make_shared_array_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run make_shared_arrays_test.cpp ; # <cxxflags>-fno-deduce-init-list no longer needed for gcc-4.6
|
||||
run make_shared_array_throws_test.cpp ;
|
||||
run make_shared_array_esft_test.cpp ;
|
||||
run make_shared_array_noinit_test.cpp ;
|
||||
run make_shared_array_value_test.cpp ;
|
||||
run make_shared_array_throws_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run make_shared_array_esft_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run make_shared_array_noinit_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run make_shared_array_value_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run allocate_shared_array_test.cpp ;
|
||||
run allocate_shared_arrays_test.cpp ; # <cxxflags>-fno-deduce-init-list no longer needed for gcc-4.6
|
||||
run allocate_shared_array_throws_test.cpp ;
|
||||
run allocate_shared_array_esft_test.cpp ;
|
||||
run allocate_shared_array_noinit_test.cpp ;
|
||||
run allocate_shared_array_value_test.cpp ;
|
||||
run allocate_shared_array_throws_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run allocate_shared_array_esft_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run allocate_shared_array_noinit_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run allocate_shared_array_value_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
run allocate_shared_array_construct_test.cpp ;
|
||||
|
||||
run make_unique_test.cpp ;
|
||||
@@ -236,7 +236,7 @@ run shared_ptr_fn_test.cpp ;
|
||||
run get_deleter_test2.cpp ;
|
||||
run get_deleter_test3.cpp ;
|
||||
run get_deleter_array_test2.cpp ;
|
||||
run get_deleter_array_test3.cpp ;
|
||||
run get_deleter_array_test3.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
|
||||
run sp_convertible_test2.cpp ;
|
||||
|
||||
@@ -275,7 +275,7 @@ run local_sp_fn_test.cpp ;
|
||||
run lsp_convertible_test.cpp ;
|
||||
run lsp_convertible_test2.cpp ;
|
||||
|
||||
run make_shared_array_tmp_test.cpp ;
|
||||
run make_shared_array_tmp_test.cpp : : : <toolset>msvc-8.0:<build>no ;
|
||||
|
||||
run lw_thread_test.cpp : : : <threading>multi ;
|
||||
|
||||
@@ -306,3 +306,16 @@ run abi_test_main.cpp abi_test_nt : : : : abi_test_mt_nt ;
|
||||
|
||||
run abi_test_main.cpp abi_test_mt/<cxxstd>0x : : : <cxxstd>98 : abi_test_03_11 ;
|
||||
run abi_test_main.cpp abi_test_mt/<cxxstd>98 : : : <cxxstd>0x : abi_test_11_03 ;
|
||||
|
||||
run weak_ptr_alias_test.cpp ;
|
||||
run weak_ptr_alias_move_test.cpp ;
|
||||
|
||||
run sp_typeinfo_test.cpp : : : <rtti>off : sp_typeinfo_test_no_rtti ;
|
||||
|
||||
run get_deleter_test.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test_no_rtti ;
|
||||
run get_deleter_test2.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test2_no_rtti ;
|
||||
run get_deleter_test3.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test3_no_rtti ;
|
||||
|
||||
run shared_from_test.cpp ;
|
||||
run weak_from_test.cpp ;
|
||||
run weak_from_test2.cpp ;
|
||||
|
@@ -41,7 +41,7 @@ class base
|
||||
{
|
||||
private:
|
||||
|
||||
boost::detail::atomic_count use_count_;
|
||||
mutable boost::detail::atomic_count use_count_;
|
||||
|
||||
base(base const &);
|
||||
base & operator=(base const &);
|
||||
@@ -69,24 +69,24 @@ public:
|
||||
|
||||
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
||||
|
||||
inline friend void intrusive_ptr_add_ref(base * p)
|
||||
inline friend void intrusive_ptr_add_ref(base const * p)
|
||||
{
|
||||
++p->use_count_;
|
||||
}
|
||||
|
||||
inline friend void intrusive_ptr_release(base * p)
|
||||
inline friend void intrusive_ptr_release(base const * p)
|
||||
{
|
||||
if(--p->use_count_ == 0) delete p;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void add_ref()
|
||||
void add_ref() const
|
||||
{
|
||||
++use_count_;
|
||||
}
|
||||
|
||||
void release()
|
||||
void release() const
|
||||
{
|
||||
if(--use_count_ == 0) delete this;
|
||||
}
|
||||
@@ -103,12 +103,12 @@ long base::instances = 0;
|
||||
namespace boost
|
||||
{
|
||||
|
||||
inline void intrusive_ptr_add_ref(N::base * p)
|
||||
inline void intrusive_ptr_add_ref(N::base const * p)
|
||||
{
|
||||
p->add_ref();
|
||||
}
|
||||
|
||||
inline void intrusive_ptr_release(N::base * p)
|
||||
inline void intrusive_ptr_release(N::base const * p)
|
||||
{
|
||||
p->release();
|
||||
}
|
||||
@@ -209,6 +209,58 @@ int main()
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<X> px( new Y );
|
||||
|
||||
X * px2 = px.get();
|
||||
|
||||
boost::intrusive_ptr<Y> py = boost::static_pointer_cast<Y>( std::move( px ) );
|
||||
BOOST_TEST( py.get() == px2 );
|
||||
BOOST_TEST( px.get() == 0 );
|
||||
BOOST_TEST( py->use_count() == 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<X const> px( new X );
|
||||
|
||||
X const * px2 = px.get();
|
||||
|
||||
boost::intrusive_ptr<X> px3 = boost::const_pointer_cast<X>( std::move( px ) );
|
||||
BOOST_TEST( px3.get() == px2 );
|
||||
BOOST_TEST( px.get() == 0 );
|
||||
BOOST_TEST( px3->use_count() == 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<X> px( new Y );
|
||||
|
||||
X * px2 = px.get();
|
||||
|
||||
boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( std::move( px ) );
|
||||
BOOST_TEST( py.get() == px2 );
|
||||
BOOST_TEST( px.get() == 0 );
|
||||
BOOST_TEST( py->use_count() == 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<X> px( new X );
|
||||
|
||||
X * px2 = px.get();
|
||||
|
||||
boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( std::move( px ) );
|
||||
BOOST_TEST( py.get() == 0 );
|
||||
BOOST_TEST( px.get() == px2 );
|
||||
BOOST_TEST( px->use_count() == 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,10 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ > 4
|
||||
# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
|
||||
#endif
|
||||
|
||||
#include <boost/smart_ptr/enable_shared_from_raw.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
|
102
test/shared_from_test.cpp
Normal file
102
test/shared_from_test.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
// shared_from_test.cpp
|
||||
//
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/smart_ptr/enable_shared_from.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
//
|
||||
|
||||
class X
|
||||
{
|
||||
private:
|
||||
|
||||
int m_;
|
||||
|
||||
public:
|
||||
|
||||
X(): m_() {}
|
||||
};
|
||||
|
||||
class Y: public boost::enable_shared_from
|
||||
{
|
||||
};
|
||||
|
||||
class Z: public X, public Y
|
||||
{
|
||||
public:
|
||||
|
||||
boost::shared_ptr<Z> shared_from_this()
|
||||
{
|
||||
return boost::shared_from( this );
|
||||
}
|
||||
};
|
||||
|
||||
void null_deleter( void const* )
|
||||
{
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<Z> p( new Z );
|
||||
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<Z> q = p->shared_from_this();
|
||||
|
||||
BOOST_TEST_EQ( p, q );
|
||||
BOOST_TEST( !( p < q ) && !( q < p ) );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const & )
|
||||
{
|
||||
BOOST_ERROR( "p->shared_from_this() failed" );
|
||||
}
|
||||
|
||||
Z v2( *p );
|
||||
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<Z> q = v2.shared_from_this();
|
||||
BOOST_ERROR( "v2.shared_from_this() failed to throw" );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const & )
|
||||
{
|
||||
}
|
||||
|
||||
*p = Z();
|
||||
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<Z> q = p->shared_from_this();
|
||||
|
||||
BOOST_TEST_EQ( p, q );
|
||||
BOOST_TEST( !( p < q ) && !( q < p ) );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const & )
|
||||
{
|
||||
BOOST_ERROR( "p->shared_from_this() threw bad_weak_ptr after *p = Z()" );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<Z> p2( p.get(), null_deleter );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<Z> q = p->shared_from_this();
|
||||
|
||||
BOOST_TEST_EQ( p, q );
|
||||
BOOST_TEST( !( p < q ) && !( q < p ) );
|
||||
}
|
||||
catch( boost::bad_weak_ptr const& )
|
||||
{
|
||||
BOOST_ERROR( "p->shared_from_this() failed" );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@@ -7,6 +7,10 @@
|
||||
#pragma warning(disable: 4514) // unreferenced inline removed
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ > 4
|
||||
# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
|
||||
#endif
|
||||
|
||||
//
|
||||
// shared_from_this_test.cpp
|
||||
//
|
||||
|
@@ -14,6 +14,10 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ > 4
|
||||
# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
|
||||
#endif
|
||||
|
||||
//
|
||||
// shared_ptr_basic_test.cpp
|
||||
//
|
||||
|
@@ -14,6 +14,10 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ > 4
|
||||
# pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
|
||||
#endif
|
||||
|
||||
//
|
||||
// shared_ptr_test.cpp
|
||||
//
|
||||
|
@@ -8,19 +8,19 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( BOOST_SP_TYPEID( int ) == BOOST_SP_TYPEID( int ) );
|
||||
BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( long ) );
|
||||
BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( void ) );
|
||||
BOOST_TEST( BOOST_SP_TYPEID_( int ) == BOOST_SP_TYPEID_( int ) );
|
||||
BOOST_TEST( BOOST_SP_TYPEID_( int ) != BOOST_SP_TYPEID_( long ) );
|
||||
BOOST_TEST( BOOST_SP_TYPEID_( int ) != BOOST_SP_TYPEID_( void ) );
|
||||
|
||||
boost::detail::sp_typeinfo const & ti = BOOST_SP_TYPEID( int );
|
||||
boost::detail::sp_typeinfo_ const & ti = BOOST_SP_TYPEID_( int );
|
||||
|
||||
boost::detail::sp_typeinfo const * pti = &BOOST_SP_TYPEID( int );
|
||||
boost::detail::sp_typeinfo_ const * pti = &BOOST_SP_TYPEID_( int );
|
||||
BOOST_TEST( *pti == ti );
|
||||
|
||||
BOOST_TEST( ti == ti );
|
||||
@@ -30,9 +30,9 @@ int main()
|
||||
char const * nti = ti.name();
|
||||
std::cout << nti << std::endl;
|
||||
|
||||
boost::detail::sp_typeinfo const & tv = BOOST_SP_TYPEID( void );
|
||||
boost::detail::sp_typeinfo_ const & tv = BOOST_SP_TYPEID_( void );
|
||||
|
||||
boost::detail::sp_typeinfo const * ptv = &BOOST_SP_TYPEID( void );
|
||||
boost::detail::sp_typeinfo_ const * ptv = &BOOST_SP_TYPEID_( void );
|
||||
BOOST_TEST( *ptv == tv );
|
||||
|
||||
BOOST_TEST( tv == tv );
|
||||
|
97
test/weak_from_test.cpp
Normal file
97
test/weak_from_test.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
// weak_from_test.cpp
|
||||
//
|
||||
// Copyright 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/smart_ptr/enable_shared_from.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
//
|
||||
|
||||
class X
|
||||
{
|
||||
private:
|
||||
|
||||
int m_;
|
||||
|
||||
public:
|
||||
|
||||
X(): m_() {}
|
||||
};
|
||||
|
||||
class Y: public boost::enable_shared_from
|
||||
{
|
||||
};
|
||||
|
||||
class Z: public X, public Y
|
||||
{
|
||||
public:
|
||||
|
||||
boost::weak_ptr<Z> weak_from_this()
|
||||
{
|
||||
return boost::weak_from( this );
|
||||
}
|
||||
};
|
||||
|
||||
void null_deleter( void const* )
|
||||
{
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_ptr<Z> sp( new Z );
|
||||
boost::weak_ptr<Z> p( sp );
|
||||
|
||||
{
|
||||
boost::weak_ptr<Z> q = sp->weak_from_this();
|
||||
|
||||
BOOST_TEST_EQ( p.lock(), q.lock() );
|
||||
BOOST_TEST( !( p < q ) && !( q < p ) );
|
||||
}
|
||||
|
||||
Z v2( *sp );
|
||||
|
||||
{
|
||||
boost::weak_ptr<Z> q = v2.weak_from_this();
|
||||
BOOST_TEST( q.expired() );
|
||||
}
|
||||
|
||||
*sp = Z();
|
||||
|
||||
{
|
||||
boost::weak_ptr<Z> q = sp->weak_from_this();
|
||||
|
||||
BOOST_TEST_EQ( p.lock(), q.lock() );
|
||||
BOOST_TEST( !( p < q ) && !( q < p ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<Z> sp2( sp.get(), null_deleter );
|
||||
}
|
||||
|
||||
{
|
||||
boost::weak_ptr<Z> q = sp->weak_from_this();
|
||||
|
||||
BOOST_TEST_EQ( p.lock(), q.lock() );
|
||||
BOOST_TEST( !( p < q ) && !( q < p ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::weak_ptr<Z> p2 = sp->weak_from_this();
|
||||
|
||||
BOOST_TEST( !p.expired() );
|
||||
BOOST_TEST( !p2.expired() );
|
||||
|
||||
sp.reset();
|
||||
|
||||
BOOST_TEST( p.expired() );
|
||||
BOOST_TEST( p2.expired() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
57
test/weak_from_test2.cpp
Normal file
57
test/weak_from_test2.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
// weak_from_test2.cpp
|
||||
//
|
||||
// Tests weak_from in a destructor
|
||||
//
|
||||
// Copyright 2014, 2015, 2019 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/smart_ptr/enable_shared_from.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
class X: public boost::enable_shared_from
|
||||
{
|
||||
private:
|
||||
|
||||
boost::weak_ptr<X> px_;
|
||||
|
||||
public:
|
||||
|
||||
X()
|
||||
{
|
||||
boost::weak_ptr<X> p1 = weak_from( this );
|
||||
BOOST_TEST( p1._empty() );
|
||||
BOOST_TEST( p1.expired() );
|
||||
}
|
||||
|
||||
void check()
|
||||
{
|
||||
boost::weak_ptr<X> p2 = weak_from( this );
|
||||
BOOST_TEST( !p2.expired() );
|
||||
|
||||
BOOST_TEST( p2.lock().get() == this );
|
||||
|
||||
px_ = p2;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
boost::weak_ptr<X> p3 = weak_from( this );
|
||||
BOOST_TEST( p3.expired() );
|
||||
|
||||
BOOST_TEST( !(px_ < p3) && !(p3 < px_) );
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr< X > px( new X );
|
||||
px->check();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@@ -39,7 +39,7 @@ void test()
|
||||
|
||||
*p = V();
|
||||
|
||||
boost::weak_ptr<V> q4 = p->shared_from_this();
|
||||
boost::weak_ptr<V> q4 = p->weak_from_this();
|
||||
BOOST_TEST( !q4.expired() );
|
||||
BOOST_TEST( !(q < q4) && !(q4 < q) );
|
||||
BOOST_TEST( !(q2 < q4) && !(q4 < q2) );
|
||||
|
97
test/weak_ptr_alias_move_test.cpp
Normal file
97
test/weak_ptr_alias_move_test.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
// weak_ptr_alias_move_test.cpp
|
||||
//
|
||||
// Copyright 2007, 2019 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/core/lightweight_test.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
class incomplete;
|
||||
|
||||
struct X
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v )
|
||||
{
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
v_ = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template<class P1, class P2> bool share_ownership( P1 const& p1, P2 const& p2 )
|
||||
{
|
||||
return !p1.owner_before( p2 ) && !p2.owner_before( p1 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<float> p( new float );
|
||||
boost::weak_ptr<float> p2( p );
|
||||
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int const volatile> p3( std::move( p2 ), &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
|
||||
BOOST_TEST( p2.empty() );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<incomplete> p;
|
||||
boost::weak_ptr<incomplete> p2( p );
|
||||
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int const volatile> p3( std::move( p2 ), &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
|
||||
BOOST_TEST( p2.empty() );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<X> p( new X( 5 ) );
|
||||
boost::weak_ptr<X> p2( p );
|
||||
|
||||
boost::weak_ptr<int const volatile> p3( std::move( p2 ), &p2.lock()->v_ );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &p->v_ );
|
||||
|
||||
BOOST_TEST( p2.empty() );
|
||||
|
||||
p.reset();
|
||||
BOOST_TEST( p3.expired() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
203
test/weak_ptr_alias_test.cpp
Normal file
203
test/weak_ptr_alias_test.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
|
||||
// weak_ptr_alias_test.cpp
|
||||
//
|
||||
// Copyright 2007, 2019 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/core/lightweight_test.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
|
||||
//
|
||||
|
||||
class incomplete;
|
||||
|
||||
struct X
|
||||
{
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v )
|
||||
{
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
v_ = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template<class P1, class P2> bool share_ownership( P1 const& p1, P2 const& p2 )
|
||||
{
|
||||
return !p1.owner_before( p2 ) && !p2.owner_before( p1 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<double> p( new double );
|
||||
|
||||
float m = 0;
|
||||
boost::weak_ptr<float> p2( p, &m );
|
||||
|
||||
BOOST_TEST( p2.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p2 ) );
|
||||
BOOST_TEST( p2.lock().get() == &m );
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int const> p3( p, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int volatile> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void> p3( p, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void const volatile> p3( p, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void const volatile> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == &m2 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<incomplete> p;
|
||||
|
||||
float m = 0;
|
||||
boost::weak_ptr<float> p2( p, &m );
|
||||
|
||||
BOOST_TEST( p2.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p2 ) );
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int const> p3( p, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<int volatile> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void> p3( p, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void const volatile> p3( p, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int m2 = 0;
|
||||
boost::weak_ptr<void const volatile> p3( p2, &m2 );
|
||||
|
||||
BOOST_TEST( p3.use_count() == p2.use_count() );
|
||||
BOOST_TEST( share_ownership( p2, p3 ) );
|
||||
BOOST_TEST( p3.lock().get() == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<X> p( new X( 5 ) );
|
||||
|
||||
boost::weak_ptr<int const> p2( p, &p->v_ );
|
||||
|
||||
BOOST_TEST( p2.use_count() == p.use_count() );
|
||||
BOOST_TEST( share_ownership( p, p2 ) );
|
||||
BOOST_TEST( p2.lock().get() == &p->v_ );
|
||||
|
||||
p.reset();
|
||||
BOOST_TEST( p2.expired() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user