mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-04 19:51:02 +02:00
Compare commits
112 Commits
boost-1.60
...
boost-1.64
Author | SHA1 | Date | |
---|---|---|---|
|
0085752a56 | ||
|
d7ad42724d | ||
|
83d3f07b0d | ||
|
994f39f9b0 | ||
|
f45dd4d955 | ||
|
b4abcdb016 | ||
|
25cf644f60 | ||
|
71ef7850ab | ||
|
40c0ddcbd6 | ||
|
687d31b7c8 | ||
|
fac6fbe3cf | ||
|
d3b9ee7d24 | ||
|
650537da60 | ||
|
324347b9ec | ||
|
79e675c727 | ||
|
6ef791c715 | ||
|
15ed558a29 | ||
|
106ada7770 | ||
|
9f70f6619f | ||
|
494c0cd2c0 | ||
|
8c058dfeee | ||
|
0807efa91a | ||
|
bea0fc4a37 | ||
|
3f21bac34f | ||
|
7beb91fd0e | ||
|
d1bb87d34e | ||
|
7570340d70 | ||
|
b42acf77b3 | ||
|
1f9c63c34f | ||
|
f8524c42a8 | ||
|
52fbf70879 | ||
|
fb59cd574e | ||
|
c749052162 | ||
|
970e88897c | ||
|
609de5d711 | ||
|
d641b9c436 | ||
|
3bb4e4d2df | ||
|
5ab9a77d50 | ||
|
b80ffbeb3d | ||
|
5f8c2a7ee0 | ||
|
94634cb853 | ||
|
17a07a228e | ||
|
d4bc4c9733 | ||
|
1d7f6b9bfd | ||
|
d718d21d6b | ||
|
39b14fa0d6 | ||
|
19147212a9 | ||
|
53928bcc12 | ||
|
9e568dad6e | ||
|
ebd1788f2c | ||
|
3e2ac10e94 | ||
|
61075bb9df | ||
|
3e61a63f60 | ||
|
a7fbb0a841 | ||
|
1e9e2ed6aa | ||
|
bdc19dee01 | ||
|
3aa720714d | ||
|
94a04e57fb | ||
|
776b33ec09 | ||
|
5595622c3e | ||
|
2ae3e4ba44 | ||
|
b5498d944e | ||
|
8fac3c9f2f | ||
|
a14515a364 | ||
|
190c06e25d | ||
|
62a8a9d6cc | ||
|
48401806f4 | ||
|
02de302774 | ||
|
80597b379e | ||
|
840e9fc96e | ||
|
70367e848e | ||
|
e8daeaee1c | ||
|
3b9ae9fd5f | ||
|
20fedcff2c | ||
|
de38a735ea | ||
|
ce52fb1045 | ||
|
6b787f1cec | ||
|
2185c4f005 | ||
|
6d5f554baa | ||
|
f3279d24b4 | ||
|
c87b6e8af8 | ||
|
aaded4f85c | ||
|
eb1a002e34 | ||
|
3304a56101 | ||
|
181f38682f | ||
|
5b1a8412c3 | ||
|
e52905cf3c | ||
|
b7f99ceba6 | ||
|
a7ade6f062 | ||
|
097d2e9bf9 | ||
|
d44a78d671 | ||
|
582eb63cb3 | ||
|
181b449a57 | ||
|
da8de3e95b | ||
|
6c27833099 | ||
|
83e6e00456 | ||
|
522f6c1869 | ||
|
cd8de9d4a6 | ||
|
e26542272d | ||
|
e13beef5df | ||
|
8298952a12 | ||
|
821925c536 | ||
|
427124543b | ||
|
46f00ea993 | ||
|
4473bf8ec2 | ||
|
7a7ac4512e | ||
|
38b6334e36 | ||
|
7af503d3bb | ||
|
05d5a4e9a0 | ||
|
970a179ac2 | ||
|
fd543d3292 | ||
|
334654de06 |
274
.travis.yml
Normal file
274
.travis.yml
Normal file
@@ -0,0 +1,274 @@
|
||||
# Copyright 2016 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BOGUS_JOB=true
|
||||
|
||||
matrix:
|
||||
|
||||
exclude:
|
||||
- env: BOGUS_JOB=true
|
||||
|
||||
include:
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=c++03
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.6
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.6
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++14
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b $TRAVIS_BRANCH https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule init libs/align
|
||||
- git submodule init libs/assert
|
||||
- git submodule init libs/atomic
|
||||
- git submodule init libs/config
|
||||
- git submodule init libs/core
|
||||
- git submodule init libs/detail
|
||||
- git submodule init libs/functional
|
||||
- git submodule init libs/integer
|
||||
- git submodule init libs/move
|
||||
- git submodule init libs/predef
|
||||
- git submodule init libs/preprocessor
|
||||
- git submodule init libs/static_assert
|
||||
- git submodule init libs/throw_exception
|
||||
- git submodule init libs/type_traits
|
||||
- git submodule init tools/build
|
||||
- git submodule update
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/smart_ptr
|
||||
- ./bootstrap.sh
|
||||
- ./b2 headers
|
||||
|
||||
script:
|
||||
- |-
|
||||
echo "using $TOOLSET : : $COMPILER : <cxxflags>-std=$CXXSTD ;" > ~/user-config.jam
|
||||
- ./b2 libs/smart_ptr/test toolset=$TOOLSET
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Boost.SmartPtr
|
||||
|
||||
Branch | Travis | Appveyor
|
||||
---------|--------|---------
|
||||
Develop | [](https://travis-ci.org/boostorg/smart_ptr) | [](https://ci.appveyor.com/project/pdimov/smart_ptr)
|
||||
Master | [](https://travis-ci.org/boostorg/smart_ptr) | [](https://ci.appveyor.com/project/pdimov/smart_ptr)
|
41
appveyor.yml
Normal file
41
appveyor.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright 2016 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
version: 1.0.{build}-{branch}
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule init libs/align
|
||||
- git submodule init libs/assert
|
||||
- git submodule init libs/atomic
|
||||
- git submodule init libs/config
|
||||
- git submodule init libs/core
|
||||
- git submodule init libs/detail
|
||||
- git submodule init libs/functional
|
||||
- git submodule init libs/integer
|
||||
- git submodule init libs/move
|
||||
- git submodule init libs/predef
|
||||
- git submodule init libs/preprocessor
|
||||
- git submodule init libs/static_assert
|
||||
- git submodule init libs/throw_exception
|
||||
- git submodule init libs/type_traits
|
||||
- git submodule init tools/build
|
||||
- git submodule update
|
||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\smart_ptr
|
||||
- bootstrap
|
||||
- b2 headers
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- b2 libs/smart_ptr/test toolset=msvc-9.0,msvc-10.0,msvc-11.0,msvc-14.0
|
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_MAKE_UNIQUE_HPP_INCLUDED
|
||||
#define BOOST_MAKE_UNIQUE_HPP_INCLUDED
|
||||
|
||||
|
@@ -10,6 +10,8 @@
|
||||
#ifndef BOOST_POINTER_CAST_HPP
|
||||
#define BOOST_POINTER_CAST_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
//static_pointer_cast overload for raw pointers
|
||||
@@ -42,4 +44,78 @@ inline T* reinterpret_pointer_cast(U *ptr)
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_SMART_PTR )
|
||||
|
||||
#include <boost/type_traits/has_virtual_destructor.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace boost {
|
||||
|
||||
//static_pointer_cast overload for std::shared_ptr
|
||||
using std::static_pointer_cast;
|
||||
|
||||
//dynamic_pointer_cast overload for std::shared_ptr
|
||||
using std::dynamic_pointer_cast;
|
||||
|
||||
//const_pointer_cast overload for std::shared_ptr
|
||||
using std::const_pointer_cast;
|
||||
|
||||
//reinterpret_pointer_cast overload for std::shared_ptr
|
||||
template<class T, class U> std::shared_ptr<T> reinterpret_pointer_cast(const std::shared_ptr<U> & r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename std::shared_ptr<T>::element_type E;
|
||||
|
||||
E * p = reinterpret_cast< E* >( r.get() );
|
||||
return std::shared_ptr<T>( r, p );
|
||||
}
|
||||
|
||||
//static_pointer_cast overload for std::unique_ptr
|
||||
template<class T, class U> std::unique_ptr<T> static_pointer_cast( std::unique_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) static_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename std::unique_ptr<T>::element_type E;
|
||||
|
||||
return std::unique_ptr<T>( static_cast<E*>( r.release() ) );
|
||||
}
|
||||
|
||||
//dynamic_pointer_cast overload for std::unique_ptr
|
||||
template<class T, class U> std::unique_ptr<T> dynamic_pointer_cast( std::unique_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
BOOST_STATIC_ASSERT_MSG( boost::has_virtual_destructor<T>::value, "The target of dynamic_pointer_cast must have a virtual destructor." );
|
||||
|
||||
T * p = dynamic_cast<T*>( r.get() );
|
||||
if( p ) r.release();
|
||||
return std::unique_ptr<T>( p );
|
||||
}
|
||||
|
||||
//const_pointer_cast overload for std::unique_ptr
|
||||
template<class T, class U> std::unique_ptr<T> const_pointer_cast( std::unique_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) const_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename std::unique_ptr<T>::element_type E;
|
||||
|
||||
return std::unique_ptr<T>( const_cast<E*>( r.release() ) );
|
||||
}
|
||||
|
||||
//reinterpret_pointer_cast overload for std::unique_ptr
|
||||
template<class T, class U> std::unique_ptr<T> reinterpret_pointer_cast( std::unique_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename std::unique_ptr<T>::element_type E;
|
||||
|
||||
return std::unique_ptr<T>( reinterpret_cast<E*>( r.release() ) );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #if !defined( BOOST_NO_CXX11_SMART_PTR )
|
||||
|
||||
#endif //BOOST_POINTER_CAST_HPP
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,11 @@ namespace boost
|
||||
# pragma option push -pc
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wweak-vtables"
|
||||
#endif
|
||||
|
||||
class bad_weak_ptr: public std::exception
|
||||
{
|
||||
public:
|
||||
@@ -46,6 +51,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__) && __BORLANDC__ <= 0x564
|
||||
# pragma option pop
|
||||
#endif
|
||||
|
@@ -1,318 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_ALLOCATOR_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_ARRAY_ALLOCATOR_HPP
|
||||
|
||||
#include <boost/align/align.hpp>
|
||||
#include <boost/smart_ptr/detail/array_traits.hpp>
|
||||
#include <boost/smart_ptr/detail/array_utility.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
struct ms_init_tag { };
|
||||
struct ms_noinit_tag { };
|
||||
|
||||
template<class T>
|
||||
struct ms_allocator_state;
|
||||
|
||||
template<class T>
|
||||
struct ms_allocator_state<T[]> {
|
||||
typedef typename array_base<T>::type type;
|
||||
|
||||
ms_allocator_state(std::size_t size_,
|
||||
type** result_)
|
||||
: size(size_ * array_total<T>::size),
|
||||
result(result_) {
|
||||
}
|
||||
|
||||
std::size_t size;
|
||||
|
||||
union {
|
||||
type** result;
|
||||
type* object;
|
||||
};
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct ms_allocator_state<T[N]> {
|
||||
typedef typename array_base<T>::type type;
|
||||
|
||||
ms_allocator_state(type** result_)
|
||||
: result(result_) {
|
||||
}
|
||||
|
||||
enum {
|
||||
size = array_total<T[N]>::size
|
||||
};
|
||||
|
||||
union {
|
||||
type** result;
|
||||
type* object;
|
||||
};
|
||||
};
|
||||
|
||||
template<class A, class T, class R>
|
||||
class as_allocator
|
||||
: public A {
|
||||
template<class A_, class T_, class R_>
|
||||
friend class as_allocator;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef std::allocator_traits<A> AT;
|
||||
typedef typename AT::template rebind_alloc<char> CA;
|
||||
typedef typename AT::template rebind_traits<char> CT;
|
||||
#else
|
||||
typedef typename A::template rebind<char>::other CA;
|
||||
#endif
|
||||
|
||||
public:
|
||||
typedef A allocator_type;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef typename AT::value_type value_type;
|
||||
typedef typename AT::pointer pointer;
|
||||
typedef typename AT::const_pointer const_pointer;
|
||||
typedef typename AT::void_pointer void_pointer;
|
||||
typedef typename AT::const_void_pointer const_void_pointer;
|
||||
typedef typename AT::size_type size_type;
|
||||
typedef typename AT::difference_type difference_type;
|
||||
#else
|
||||
typedef typename A::value_type value_type;
|
||||
typedef typename A::pointer pointer;
|
||||
typedef typename A::const_pointer const_pointer;
|
||||
typedef typename A::size_type size_type;
|
||||
typedef typename A::difference_type difference_type;
|
||||
typedef typename A::reference reference;
|
||||
typedef typename A::const_reference const_reference;
|
||||
typedef void* void_pointer;
|
||||
typedef const void* const_void_pointer;
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef as_allocator<typename AT::
|
||||
template rebind_alloc<U>, T, R> other;
|
||||
#else
|
||||
typedef as_allocator<typename A::
|
||||
template rebind<U>::other, T, R> other;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef typename array_base<T>::type type;
|
||||
|
||||
as_allocator(const A& allocator_, type** result)
|
||||
: A(allocator_),
|
||||
data(result) {
|
||||
}
|
||||
|
||||
as_allocator(const A& allocator_, std::size_t size,
|
||||
type** result)
|
||||
: A(allocator_),
|
||||
data(size, result) {
|
||||
}
|
||||
|
||||
template<class U>
|
||||
as_allocator(const as_allocator<U, T, R>& other)
|
||||
: A(other.allocator()),
|
||||
data(other.data) {
|
||||
}
|
||||
|
||||
pointer allocate(size_type count, const_void_pointer = 0) {
|
||||
enum {
|
||||
M = boost::alignment_of<type>::value
|
||||
};
|
||||
std::size_t n1 = count * sizeof(value_type);
|
||||
std::size_t n2 = data.size * sizeof(type);
|
||||
std::size_t n3 = n2 + M;
|
||||
CA ca(allocator());
|
||||
void* p1 = ca.allocate(n1 + n3);
|
||||
void* p2 = static_cast<char*>(p1) + n1;
|
||||
(void)boost::alignment::align(M, n2, p2, n3);
|
||||
*data.result = static_cast<type*>(p2);
|
||||
return static_cast<value_type*>(p1);
|
||||
}
|
||||
|
||||
void deallocate(pointer memory, size_type count) {
|
||||
enum {
|
||||
M = boost::alignment_of<type>::value
|
||||
};
|
||||
std::size_t n1 = count * sizeof(value_type);
|
||||
std::size_t n2 = data.size * sizeof(type) + M;
|
||||
char* p1 = reinterpret_cast<char*>(memory);
|
||||
CA ca(allocator());
|
||||
ca.deallocate(p1, n1 + n2);
|
||||
}
|
||||
|
||||
const A& allocator() const {
|
||||
return static_cast<const A&>(*this);
|
||||
}
|
||||
|
||||
A& allocator() {
|
||||
return static_cast<A&>(*this);
|
||||
}
|
||||
|
||||
void set(type* memory) {
|
||||
data.object = memory;
|
||||
}
|
||||
|
||||
void operator()() {
|
||||
if (data.object) {
|
||||
R tag;
|
||||
release(tag);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void release(ms_init_tag) {
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
as_destroy(allocator(), data.object, data.size);
|
||||
#else
|
||||
ms_destroy(data.object, data.size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void release(ms_noinit_tag) {
|
||||
ms_destroy(data.object, data.size);
|
||||
}
|
||||
|
||||
ms_allocator_state<T> data;
|
||||
};
|
||||
|
||||
template<class A1, class A2, class T, class R>
|
||||
bool operator==(const as_allocator<A1, T, R>& a1,
|
||||
const as_allocator<A2, T, R>& a2) {
|
||||
return a1.allocator() == a2.allocator();
|
||||
}
|
||||
|
||||
template<class A1, class A2, class T, class R>
|
||||
bool operator!=(const as_allocator<A1, T, R>& a1,
|
||||
const as_allocator<A2, T, R>& a2) {
|
||||
return a1.allocator() != a2.allocator();
|
||||
}
|
||||
|
||||
template<class T, class Y = char>
|
||||
class ms_allocator;
|
||||
|
||||
template<class T, class Y>
|
||||
class ms_allocator {
|
||||
template<class T_, class Y_>
|
||||
friend class ms_allocator;
|
||||
|
||||
public:
|
||||
typedef typename array_base<T>::type type;
|
||||
|
||||
typedef Y value_type;
|
||||
typedef Y* pointer;
|
||||
typedef const Y* const_pointer;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef Y& reference;
|
||||
typedef const Y& const_reference;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef ms_allocator<T, U> other;
|
||||
};
|
||||
|
||||
ms_allocator(type** result)
|
||||
: data(result) {
|
||||
}
|
||||
|
||||
ms_allocator(std::size_t size, type** result)
|
||||
: data(size, result) {
|
||||
}
|
||||
|
||||
template<class U>
|
||||
ms_allocator(const ms_allocator<T, U>& other)
|
||||
: data(other.data) {
|
||||
}
|
||||
|
||||
pointer allocate(size_type count, const void* = 0) {
|
||||
enum {
|
||||
M = boost::alignment_of<type>::value
|
||||
};
|
||||
std::size_t n1 = count * sizeof(Y);
|
||||
std::size_t n2 = data.size * sizeof(type);
|
||||
std::size_t n3 = n2 + M;
|
||||
void* p1 = ::operator new(n1 + n3);
|
||||
void* p2 = static_cast<char*>(p1) + n1;
|
||||
(void)boost::alignment::align(M, n2, p2, n3);
|
||||
*data.result = static_cast<type*>(p2);
|
||||
return static_cast<Y*>(p1);
|
||||
}
|
||||
|
||||
void deallocate(pointer memory, size_type) {
|
||||
void* p1 = memory;
|
||||
::operator delete(p1);
|
||||
}
|
||||
|
||||
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
pointer address(reference value) const {
|
||||
return &value;
|
||||
}
|
||||
|
||||
const_pointer address(const_reference value) const {
|
||||
return &value;
|
||||
}
|
||||
|
||||
size_type max_size() const {
|
||||
enum {
|
||||
N = static_cast<std::size_t>(-1) / sizeof(Y)
|
||||
};
|
||||
return N;
|
||||
}
|
||||
|
||||
void construct(pointer memory, const_reference value) {
|
||||
void* p1 = memory;
|
||||
::new(p1) Y(value);
|
||||
}
|
||||
|
||||
void destroy(pointer memory) {
|
||||
(void)memory;
|
||||
memory->~Y();
|
||||
}
|
||||
#endif
|
||||
|
||||
void set(type* memory) {
|
||||
data.object = memory;
|
||||
}
|
||||
|
||||
void operator()() {
|
||||
if (data.object) {
|
||||
ms_destroy(data.object, data.size);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ms_allocator_state<T> data;
|
||||
};
|
||||
|
||||
template<class T, class Y1, class Y2>
|
||||
bool operator==(const ms_allocator<T, Y1>&,
|
||||
const ms_allocator<T, Y2>&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class Y1, class Y2>
|
||||
bool operator!=(const ms_allocator<T, Y1>&,
|
||||
const ms_allocator<T, Y2>&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
class ms_in_allocator_tag {
|
||||
public:
|
||||
void operator()(const void*) {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_COUNT_IMPL_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_ARRAY_COUNT_IMPL_HPP
|
||||
|
||||
#include <boost/smart_ptr/detail/array_allocator.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_counted_impl.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template<class P, class A>
|
||||
class sp_counted_impl_pda<P, ms_in_allocator_tag, A>
|
||||
: public sp_counted_base {
|
||||
typedef ms_in_allocator_tag D;
|
||||
typedef sp_counted_impl_pda<P, D, A> Y;
|
||||
public:
|
||||
sp_counted_impl_pda(P, D, const A& allocator_)
|
||||
: allocator(allocator_) {
|
||||
}
|
||||
|
||||
virtual void dispose() {
|
||||
allocator();
|
||||
}
|
||||
|
||||
virtual void destroy() {
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_alloc<Y> YA;
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_traits<Y> YT;
|
||||
#else
|
||||
typedef typename A::template rebind<Y>::other YA;
|
||||
#endif
|
||||
YA a1(allocator);
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
YT::destroy(a1, this);
|
||||
YT::deallocate(a1, this, 1);
|
||||
#else
|
||||
this->~Y();
|
||||
a1.deallocate(this, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void* get_deleter(const sp_typeinfo&) {
|
||||
return &reinterpret_cast<char&>(allocator);
|
||||
}
|
||||
|
||||
virtual void* get_untyped_deleter() {
|
||||
return &reinterpret_cast<char&>(allocator);
|
||||
}
|
||||
|
||||
private:
|
||||
sp_counted_impl_pda(const sp_counted_impl_pda&);
|
||||
sp_counted_impl_pda& operator=(const sp_counted_impl_pda&);
|
||||
|
||||
A allocator;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP
|
||||
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template<class T>
|
||||
struct array_base {
|
||||
typedef typename boost::remove_cv<T>::type type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct array_base<T[]> {
|
||||
typedef typename array_base<T>::type type;
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct array_base<T[N]> {
|
||||
typedef typename array_base<T>::type type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct array_total {
|
||||
enum {
|
||||
size = 1
|
||||
};
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct array_total<T[N]> {
|
||||
enum {
|
||||
size = N * array_total<T>::size
|
||||
};
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct array_inner;
|
||||
|
||||
template<class T>
|
||||
struct array_inner<T[]> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct array_inner<T[N]> {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_UTILITY_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_ARRAY_UTILITY_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/type_traits/has_trivial_constructor.hpp>
|
||||
#include <boost/type_traits/has_trivial_destructor.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#include <memory>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
typedef boost::true_type ms_is_trivial;
|
||||
typedef boost::false_type ms_no_trivial;
|
||||
|
||||
template<class T>
|
||||
inline void ms_destroy(T*, std::size_t, ms_is_trivial) {
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ms_destroy(T* memory, std::size_t size, ms_no_trivial) {
|
||||
for (std::size_t i = size; i > 0;) {
|
||||
memory[--i].~T();
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ms_destroy(T* memory, std::size_t size) {
|
||||
boost::has_trivial_destructor<T> trivial;
|
||||
ms_destroy(memory, size, trivial);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ms_init(T* memory, std::size_t size, ms_is_trivial) {
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T();
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ms_init(T* memory, std::size_t size, ms_no_trivial) {
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T();
|
||||
}
|
||||
} catch (...) {
|
||||
ms_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ms_init(T* memory, std::size_t size) {
|
||||
boost::has_trivial_default_constructor<T> trivial;
|
||||
ms_init(memory, size, trivial);
|
||||
}
|
||||
|
||||
template<class T, std::size_t N>
|
||||
inline void ms_init(T* memory, std::size_t size, const T* list) {
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(list[i % N]);
|
||||
}
|
||||
} catch (...) {
|
||||
ms_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(list[i % N]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class T, class A>
|
||||
inline void as_destroy(const A& allocator, T* memory,
|
||||
std::size_t size) {
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_alloc<T> TA;
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_traits<T> TT;
|
||||
TA a2(allocator);
|
||||
for (std::size_t i = size; i > 0;) {
|
||||
TT::destroy(a2, &memory[--i]);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
inline void as_init(const A& allocator, T* memory, std::size_t size,
|
||||
ms_is_trivial) {
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_alloc<T> TA;
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_traits<T> TT;
|
||||
TA a2(allocator);
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
TT::construct(a2, memory + i);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
inline void as_init(const A& allocator, T* memory, std::size_t size,
|
||||
ms_no_trivial) {
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_alloc<T> TA;
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_traits<T> TT;
|
||||
TA a2(allocator);
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
TT::construct(a2, memory + i);
|
||||
}
|
||||
} catch (...) {
|
||||
as_destroy(a2, memory, i);
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
TT::construct(a2, memory + i);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
inline void as_init(const A& allocator, T* memory, std::size_t size) {
|
||||
boost::has_trivial_default_constructor<T> trivial;
|
||||
as_init(allocator, memory, size, trivial);
|
||||
}
|
||||
|
||||
template<class T, class A, std::size_t N>
|
||||
inline void as_init(const A& allocator, T* memory, std::size_t size,
|
||||
const T* list) {
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_alloc<T> TA;
|
||||
typedef typename std::allocator_traits<A>::
|
||||
template rebind_traits<T> TT;
|
||||
TA a2(allocator);
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
TT::construct(a2, memory + i, list[i % N]);
|
||||
}
|
||||
} catch (...) {
|
||||
as_destroy(a2, memory, i);
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
TT::construct(a2, memory + i, list[i % N]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
inline void ms_noinit(T*, std::size_t, ms_is_trivial) {
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ms_noinit(T* memory, std::size_t size, ms_no_trivial) {
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T;
|
||||
}
|
||||
} catch (...) {
|
||||
ms_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ms_noinit(T* memory, std::size_t size) {
|
||||
boost::has_trivial_default_constructor<T> trivial;
|
||||
ms_noinit(memory, size, trivial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -73,6 +73,9 @@
|
||||
#elif defined( BOOST_DISABLE_THREADS ) && !defined( BOOST_SP_ENABLE_THREADS ) && !defined( BOOST_DISABLE_WIN32 )
|
||||
# include <boost/smart_ptr/detail/atomic_count_nt.hpp>
|
||||
|
||||
#elif !defined( BOOST_NO_CXX11_HDR_ATOMIC )
|
||||
# include <boost/smart_ptr/detail/atomic_count_std_atomic.hpp>
|
||||
|
||||
#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) && !defined( __PATHSCALE__ )
|
||||
# include <boost/smart_ptr/detail/atomic_count_gcc_x86.hpp>
|
||||
|
||||
|
@@ -249,18 +249,8 @@ public:
|
||||
|
||||
try
|
||||
{
|
||||
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
|
||||
impl_type * pi = std::allocator_traits<A2>::allocate( a2, 1 );
|
||||
pi_ = pi;
|
||||
std::allocator_traits<A2>::construct( a2, pi, p, d, a );
|
||||
|
||||
#else
|
||||
|
||||
pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) );
|
||||
pi_ = a2.allocate( 1 );
|
||||
::new( static_cast< void* >( pi_ ) ) impl_type( p, d, a );
|
||||
|
||||
#endif
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@@ -276,28 +266,11 @@ public:
|
||||
|
||||
#else
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
|
||||
impl_type * pi = std::allocator_traits<A2>::allocate( a2, 1 );
|
||||
pi_ = pi;
|
||||
|
||||
#else
|
||||
|
||||
pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) );
|
||||
|
||||
#endif
|
||||
pi_ = a2.allocate( 1 );
|
||||
|
||||
if( pi_ != 0 )
|
||||
{
|
||||
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
|
||||
std::allocator_traits<A2>::construct( a2, pi, p, d, a );
|
||||
|
||||
#else
|
||||
|
||||
::new( static_cast< void* >( pi_ ) ) impl_type( p, d, a );
|
||||
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -333,18 +306,8 @@ public:
|
||||
|
||||
try
|
||||
{
|
||||
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
|
||||
impl_type * pi = std::allocator_traits<A2>::allocate( a2, 1 );
|
||||
pi_ = pi;
|
||||
std::allocator_traits<A2>::construct( a2, pi, p, a );
|
||||
|
||||
#else
|
||||
|
||||
pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) );
|
||||
pi_ = a2.allocate( 1 );
|
||||
::new( static_cast< void* >( pi_ ) ) impl_type( p, a );
|
||||
|
||||
#endif
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@@ -360,28 +323,11 @@ public:
|
||||
|
||||
#else
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
|
||||
impl_type * pi = std::allocator_traits<A2>::allocate( a2, 1 );
|
||||
pi_ = pi;
|
||||
|
||||
#else
|
||||
|
||||
pi_ = a2.allocate( 1, static_cast< impl_type* >( 0 ) );
|
||||
|
||||
#endif
|
||||
pi_ = a2.allocate( 1 );
|
||||
|
||||
if( pi_ != 0 )
|
||||
{
|
||||
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
|
||||
std::allocator_traits<A2>::construct( a2, pi, p, a );
|
||||
|
||||
#else
|
||||
|
||||
::new( static_cast< void* >( pi_ ) ) impl_type( p, a );
|
||||
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_has_sync.hpp>
|
||||
|
||||
#if defined( __clang__ ) && defined( __has_extension )
|
||||
#if !defined( __c2__ ) && defined( __clang__ ) && defined( __has_extension )
|
||||
# if __has_extension( __c_atomic__ )
|
||||
# define BOOST_SP_HAS_CLANG_C11_ATOMICS
|
||||
# endif
|
||||
@@ -44,6 +44,9 @@
|
||||
#elif defined( BOOST_SP_HAS_CLANG_C11_ATOMICS )
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_clang.hpp>
|
||||
|
||||
#elif !defined( BOOST_NO_CXX11_HDR_ATOMIC )
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp>
|
||||
|
||||
#elif defined( __SNC__ )
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp>
|
||||
|
||||
@@ -65,7 +68,7 @@
|
||||
#elif defined( __GNUC__ ) && ( defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc ) ) && !defined(__PATHSCALE__) && !defined( _AIX )
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp>
|
||||
|
||||
#elif defined( __GNUC__ ) && ( defined( __mips__ ) || defined( _mips ) ) && !defined(__PATHSCALE__)
|
||||
#elif defined( __GNUC__ ) && ( defined( __mips__ ) || defined( _mips ) ) && !defined(__PATHSCALE__) && !defined( __mips16 )
|
||||
# include <boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp>
|
||||
|
||||
#elif defined( BOOST_SP_HAS_SYNC )
|
||||
|
@@ -58,6 +58,11 @@ inline boost::int_least32_t atomic_conditional_increment( atomic_int_least32_t *
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wweak-vtables"
|
||||
#endif
|
||||
|
||||
class sp_counted_base
|
||||
{
|
||||
private:
|
||||
@@ -133,6 +138,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
@@ -236,16 +236,8 @@ public:
|
||||
|
||||
A2 a2( a_ );
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_ALLOCATOR )
|
||||
|
||||
std::allocator_traits<A2>::destroy( a2, this );
|
||||
|
||||
#else
|
||||
|
||||
this->~this_type();
|
||||
|
||||
#endif
|
||||
|
||||
a2.deallocate( this, 1 );
|
||||
}
|
||||
|
||||
|
@@ -22,15 +22,15 @@
|
||||
|
||||
#ifndef BOOST_SP_NO_SYNC
|
||||
|
||||
#if defined( __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 )
|
||||
#if !defined( __c2__ ) && defined( __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 )
|
||||
|
||||
# define BOOST_SP_HAS_SYNC
|
||||
|
||||
#elif defined( __IBMCPP__ ) && ( __IBMCPP__ >= 1210 )
|
||||
#elif defined( __IBMCPP__ ) && ( __IBMCPP__ >= 1210 ) && !defined( __COMPILER_VER__ )
|
||||
|
||||
# define BOOST_SP_HAS_SYNC
|
||||
|
||||
#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
|
||||
#elif !defined( __c2__ ) && defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
|
||||
|
||||
#define BOOST_SP_HAS_SYNC
|
||||
|
||||
|
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_SP_IF_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_SP_IF_ARRAY_HPP
|
||||
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template<class T>
|
||||
struct sp_if_array;
|
||||
|
||||
template<class T>
|
||||
struct sp_if_array<T[]> {
|
||||
typedef boost::shared_ptr<T[]> type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct sp_if_size_array;
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct sp_if_size_array<T[N]> {
|
||||
typedef boost::shared_ptr<T[N]> type;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
30
include/boost/smart_ptr/detail/sp_noexcept.hpp
Normal file
30
include/boost/smart_ptr/detail/sp_noexcept.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_SP_NOEXCEPT_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_DETAIL_SP_NOEXCEPT_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// detail/sp_noexcept.hpp
|
||||
//
|
||||
// Copyright 2016 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_MSVC ) && BOOST_MSVC >= 1700 && BOOST_MSVC < 1900
|
||||
|
||||
#define BOOST_SP_NOEXCEPT BOOST_NOEXCEPT_OR_NOTHROW
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_SP_NOEXCEPT BOOST_NOEXCEPT
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_NOEXCEPT_HPP_INCLUDED
|
@@ -43,6 +43,9 @@
|
||||
#elif defined( BOOST_SP_USE_PTHREADS )
|
||||
# include <boost/smart_ptr/detail/spinlock_pt.hpp>
|
||||
|
||||
#elif !defined( BOOST_NO_CXX11_HDR_ATOMIC )
|
||||
# include <boost/smart_ptr/detail/spinlock_std_atomic.hpp>
|
||||
|
||||
#elif defined(__GNUC__) && defined( __arm__ ) && !defined( __thumb__ )
|
||||
# include <boost/smart_ptr/detail/spinlock_gcc_arm.hpp>
|
||||
|
||||
|
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_UP_IF_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_UP_IF_ARRAY_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template<class T>
|
||||
struct up_if_array;
|
||||
|
||||
template<class T>
|
||||
struct up_if_array<T[]> {
|
||||
typedef std::unique_ptr<T[]> type;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_UP_IF_NOT_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_UP_IF_NOT_ARRAY_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template<class T>
|
||||
struct up_if_not_array {
|
||||
typedef std::unique_ptr<T> type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct up_if_not_array<T[]> {
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct up_if_not_array<T[N]> {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -104,7 +104,7 @@ private:
|
||||
}
|
||||
|
||||
// Note: invoked automatically by shared_ptr; do not call
|
||||
template<class X, class Y> void _internal_accept_owner( shared_ptr<X> * ppx, Y * py ) const
|
||||
template<class X, class Y> void _internal_accept_owner( shared_ptr<X> * ppx, Y * ) const
|
||||
{
|
||||
BOOST_ASSERT( ppx != 0 );
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
@@ -25,20 +26,20 @@ template<class T> class enable_shared_from_this
|
||||
{
|
||||
protected:
|
||||
|
||||
enable_shared_from_this() BOOST_NOEXCEPT
|
||||
enable_shared_from_this() BOOST_SP_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
enable_shared_from_this(enable_shared_from_this const &) BOOST_NOEXCEPT
|
||||
enable_shared_from_this(enable_shared_from_this const &) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
enable_shared_from_this & operator=(enable_shared_from_this const &) BOOST_NOEXCEPT
|
||||
enable_shared_from_this & operator=(enable_shared_from_this const &) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
~enable_shared_from_this() BOOST_NOEXCEPT // ~weak_ptr<T> newer throws, so this call also must not throw
|
||||
~enable_shared_from_this() BOOST_SP_NOEXCEPT // ~weak_ptr<T> newer throws, so this call also must not throw
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_convertible.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
|
||||
#include <boost/config/no_tr1/functional.hpp> // for std::less
|
||||
|
||||
@@ -59,7 +60,7 @@ public:
|
||||
|
||||
typedef T element_type;
|
||||
|
||||
intrusive_ptr() BOOST_NOEXCEPT : px( 0 )
|
||||
BOOST_CONSTEXPR intrusive_ptr() BOOST_SP_NOEXCEPT : px( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -111,17 +112,41 @@ public:
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
intrusive_ptr(intrusive_ptr && rhs) BOOST_NOEXCEPT : px( rhs.px )
|
||||
intrusive_ptr(intrusive_ptr && rhs) BOOST_SP_NOEXCEPT : px( rhs.px )
|
||||
{
|
||||
rhs.px = 0;
|
||||
}
|
||||
|
||||
intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_NOEXCEPT
|
||||
intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class U> friend class intrusive_ptr;
|
||||
|
||||
template<class U>
|
||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
|
||||
|
||||
intrusive_ptr(intrusive_ptr<U> && rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty())
|
||||
|
||||
#else
|
||||
|
||||
intrusive_ptr(intrusive_ptr<U> && rhs)
|
||||
|
||||
#endif
|
||||
: px( rhs.px )
|
||||
{
|
||||
rhs.px = 0;
|
||||
}
|
||||
|
||||
template<class U>
|
||||
intrusive_ptr & operator=(intrusive_ptr<U> && rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
this_type( static_cast< intrusive_ptr<U> && >( rhs ) ).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
intrusive_ptr & operator=(intrusive_ptr const & rhs)
|
||||
|
@@ -83,7 +83,7 @@ struct thread_safe_counter
|
||||
|
||||
static unsigned int decrement(boost::detail::atomic_count& counter) BOOST_NOEXCEPT
|
||||
{
|
||||
return --counter;
|
||||
return static_cast< unsigned int >(--counter);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -1,158 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2012-2017 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
|
||||
|
||||
#include <boost/smart_ptr/detail/array_count_impl.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_if_array.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
|
||||
namespace boost {
|
||||
template<class T>
|
||||
inline typename boost::detail::sp_if_array<T>::type
|
||||
make_shared(std::size_t size) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef boost::detail::ms_allocator<T> A1;
|
||||
typedef boost::detail::ms_in_allocator_tag D1;
|
||||
std::size_t n1 = size * boost::detail::array_total<T1>::size;
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
D1 d1;
|
||||
A1 a1(size, &p2);
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
|
||||
a2->set(0);
|
||||
boost::detail::ms_init(p2, n1);
|
||||
a2->set(p2);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
make_shared() {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef boost::detail::ms_allocator<T> A1;
|
||||
typedef boost::detail::ms_in_allocator_tag D1;
|
||||
enum {
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
D1 d1;
|
||||
A1 a1(&p2);
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
|
||||
a2->set(0);
|
||||
boost::detail::ms_init(p2, N);
|
||||
a2->set(p2);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::sp_if_array<T>::type
|
||||
make_shared(std::size_t size,
|
||||
const typename boost::detail::array_inner<T>::type& value) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
typedef boost::detail::ms_allocator<T> A1;
|
||||
typedef boost::detail::ms_in_allocator_tag D1;
|
||||
enum {
|
||||
M = boost::detail::array_total<T1>::size
|
||||
};
|
||||
std::size_t n1 = M * size;
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = reinterpret_cast<T3*>(&value);
|
||||
D1 d1;
|
||||
A1 a1(size, &p2);
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
|
||||
a2->set(0);
|
||||
boost::detail::ms_init<T2, M>(p2, n1, p3);
|
||||
a2->set(p2);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
make_shared(const typename boost::detail::array_inner<T>::type& value) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef const T2 T3;
|
||||
typedef boost::detail::ms_allocator<T> A1;
|
||||
typedef boost::detail::ms_in_allocator_tag D1;
|
||||
enum {
|
||||
M = boost::detail::array_total<T1>::size,
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
T3* p3 = reinterpret_cast<T3*>(&value);
|
||||
D1 d1;
|
||||
A1 a1(&p2);
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
|
||||
a2->set(0);
|
||||
boost::detail::ms_init<T2, M>(p2, N, p3);
|
||||
a2->set(p2);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::sp_if_array<T>::type
|
||||
make_shared_noinit(std::size_t size) {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef boost::detail::ms_allocator<T> A1;
|
||||
typedef boost::detail::ms_in_allocator_tag D1;
|
||||
std::size_t n1 = size * boost::detail::array_total<T1>::size;
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
D1 d1;
|
||||
A1 a1(size, &p2);
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
|
||||
a2->set(0);
|
||||
boost::detail::ms_noinit(p2, n1);
|
||||
a2->set(p2);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::sp_if_size_array<T>::type
|
||||
make_shared_noinit() {
|
||||
typedef typename boost::detail::array_inner<T>::type T1;
|
||||
typedef typename boost::detail::array_base<T1>::type T2;
|
||||
typedef boost::detail::ms_allocator<T> A1;
|
||||
typedef boost::detail::ms_in_allocator_tag D1;
|
||||
enum {
|
||||
N = boost::detail::array_total<T>::size
|
||||
};
|
||||
T1* p1 = 0;
|
||||
T2* p2 = 0;
|
||||
D1 d1;
|
||||
A1 a1(&p2);
|
||||
shared_ptr<T> s1(p1, d1, a1);
|
||||
A1* a2 = static_cast<A1*>(s1._internal_get_untyped_deleter());
|
||||
a2->set(0);
|
||||
boost::detail::ms_noinit(p2, N);
|
||||
a2->set(p2);
|
||||
p1 = reinterpret_cast<T1*>(p2);
|
||||
return shared_ptr<T>(s1, p1);
|
||||
}
|
||||
template<class T>
|
||||
inline typename detail::sp_if_size_array<T>::type
|
||||
make_shared()
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::sp_if_size_array<T>::type
|
||||
make_shared(const typename detail::sp_array_element<T>::type& value)
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::sp_if_array<T>::type
|
||||
make_shared(std::size_t size)
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::sp_if_array<T>::type
|
||||
make_shared(std::size_t size,
|
||||
const typename detail::sp_array_element<T>::type& value)
|
||||
{
|
||||
return boost::allocate_shared<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size, value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::sp_if_size_array<T>::type
|
||||
make_shared_noinit()
|
||||
{
|
||||
return allocate_shared_noinit<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::sp_if_array<T>::type
|
||||
make_shared_noinit(std::size_t size)
|
||||
{
|
||||
return allocate_shared_noinit<T>(std::allocator<typename
|
||||
detail::sp_array_scalar<T>::type>(), size);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
|
@@ -13,6 +13,8 @@
|
||||
// for documentation.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_forward.hpp>
|
||||
#include <boost/type_traits/type_with_alignment.hpp>
|
||||
@@ -338,466 +340,10 @@ template< class T, class A > typename boost::detail::sp_if_not_array< T >::type
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
// For example MSVC 10.0
|
||||
|
||||
template< class T, class A1 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 ),
|
||||
boost::detail::sp_forward<A9>( a9 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T(
|
||||
boost::detail::sp_forward<A1>( a1 ),
|
||||
boost::detail::sp_forward<A2>( a2 ),
|
||||
boost::detail::sp_forward<A3>( a3 ),
|
||||
boost::detail::sp_forward<A4>( a4 ),
|
||||
boost::detail::sp_forward<A5>( a5 ),
|
||||
boost::detail::sp_forward<A6>( a6 ),
|
||||
boost::detail::sp_forward<A7>( a7 ),
|
||||
boost::detail::sp_forward<A8>( a8 ),
|
||||
boost::detail::sp_forward<A9>( a9 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
|
||||
boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
#else // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
// C++03 version
|
||||
|
||||
template< class T, class A1 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -805,7 +351,10 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1 )
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -815,7 +364,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1 )
|
||||
}
|
||||
|
||||
template< class T, class A, class A1 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -823,7 +372,10 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -833,7 +385,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -841,7 +393,11 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -851,7 +407,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -859,7 +415,11 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -869,7 +429,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -877,7 +437,12 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -887,7 +452,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -895,7 +460,12 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -905,7 +475,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -913,7 +483,13 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -923,7 +499,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -931,7 +507,13 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -941,7 +523,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -949,7 +531,14 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -959,7 +548,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -967,7 +556,14 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -977,7 +573,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -985,7 +581,15 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -995,7 +599,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -1003,7 +607,15 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -1013,7 +625,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6, BOOST_FWD_REF(A7) a7 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -1021,7 +633,16 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6, a7 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 ),
|
||||
boost::forward<A7>( a7 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -1031,7 +652,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6, BOOST_FWD_REF(A7) a7 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -1039,7 +660,16 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6, a7 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 ),
|
||||
boost::forward<A7>( a7 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -1049,7 +679,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6, BOOST_FWD_REF(A7) a7, BOOST_FWD_REF(A8) a8 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -1057,7 +687,17 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 ),
|
||||
boost::forward<A7>( a7 ),
|
||||
boost::forward<A8>( a8 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -1067,7 +707,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6, BOOST_FWD_REF(A7) a7, BOOST_FWD_REF(A8) a8 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -1075,7 +715,17 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 ),
|
||||
boost::forward<A7>( a7 ),
|
||||
boost::forward<A8>( a8 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -1085,7 +735,7 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
}
|
||||
|
||||
template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8, A9 const & a9 )
|
||||
typename boost::detail::sp_if_not_array< T >::type make_shared( BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6, BOOST_FWD_REF(A7) a7, BOOST_FWD_REF(A8) a8, BOOST_FWD_REF(A9) a9 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
|
||||
|
||||
@@ -1093,7 +743,18 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 ),
|
||||
boost::forward<A7>( a7 ),
|
||||
boost::forward<A8>( a8 ),
|
||||
boost::forward<A9>( a9 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -1103,7 +764,7 @@ typename boost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A
|
||||
}
|
||||
|
||||
template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8, A9 const & a9 )
|
||||
typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2, BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(A4) a4, BOOST_FWD_REF(A5) a5, BOOST_FWD_REF(A6) a6, BOOST_FWD_REF(A7) a7, BOOST_FWD_REF(A8) a8, BOOST_FWD_REF(A9) a9 )
|
||||
{
|
||||
boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
|
||||
|
||||
@@ -1111,7 +772,18 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
|
||||
void * pv = pd->address();
|
||||
|
||||
::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
|
||||
::new( pv ) T(
|
||||
boost::forward<A1>( a1 ),
|
||||
boost::forward<A2>( a2 ),
|
||||
boost::forward<A3>( a3 ),
|
||||
boost::forward<A4>( a4 ),
|
||||
boost::forward<A5>( a5 ),
|
||||
boost::forward<A6>( a6 ),
|
||||
boost::forward<A7>( a7 ),
|
||||
boost::forward<A8>( a8 ),
|
||||
boost::forward<A9>( a9 )
|
||||
);
|
||||
|
||||
pd->set_initialized();
|
||||
|
||||
T * pt2 = static_cast< T* >( pv );
|
||||
@@ -1120,8 +792,6 @@ typename boost::detail::sp_if_not_array< T >::type allocate_shared( A const & a,
|
||||
return boost::shared_ptr< T >( pt, pt2 );
|
||||
}
|
||||
|
||||
#endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
#endif // !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
#undef BOOST_SP_MSD
|
||||
|
@@ -1,15 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
||||
#define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
||||
|
||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct up_if_object {
|
||||
typedef std::unique_ptr<T> type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct up_if_object<T[]> { };
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct up_if_object<T[N]> { };
|
||||
|
||||
template<class T>
|
||||
struct up_if_array { };
|
||||
|
||||
template<class T>
|
||||
struct up_if_array<T[]> {
|
||||
typedef std::unique_ptr<T[]> type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct up_remove_reference {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct up_remove_reference<T&> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct up_remove_reference<T&&> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct up_element { };
|
||||
|
||||
template<class T>
|
||||
struct up_element<T[]> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
} /* detail */
|
||||
|
||||
template<class T>
|
||||
inline typename detail::up_if_object<T>::type
|
||||
make_unique()
|
||||
{
|
||||
return std::unique_ptr<T>(new T());
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class T, class... Args>
|
||||
inline typename detail::up_if_object<T>::type
|
||||
make_unique(Args&&... args)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
inline typename detail::up_if_object<T>::type
|
||||
make_unique(typename detail::up_remove_reference<T>::type&& value)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::move(value)));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::up_if_object<T>::type
|
||||
make_unique_noinit()
|
||||
{
|
||||
return std::unique_ptr<T>(new T);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::up_if_array<T>::type
|
||||
make_unique(std::size_t size)
|
||||
{
|
||||
return std::unique_ptr<T>(new typename
|
||||
detail::up_element<T>::type[size]());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename detail::up_if_array<T>::type
|
||||
make_unique_noinit(std::size_t size)
|
||||
{
|
||||
return std::unique_ptr<T>(new typename
|
||||
detail::up_element<T>::type[size]);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
|
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_ARRAY_HPP
|
||||
#define BOOST_SMART_PTR_MAKE_UNIQUE_ARRAY_HPP
|
||||
|
||||
#include <boost/smart_ptr/detail/up_if_array.hpp>
|
||||
#include <boost/smart_ptr/detail/array_traits.hpp>
|
||||
|
||||
namespace boost {
|
||||
template<class T>
|
||||
inline typename boost::detail::up_if_array<T>::type
|
||||
make_unique(std::size_t size) {
|
||||
typedef typename boost::detail::array_inner<T>::type U;
|
||||
return std::unique_ptr<T>(new U[size]());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::up_if_array<T>::type
|
||||
make_unique_noinit(std::size_t size) {
|
||||
typedef typename boost::detail::array_inner<T>::type U;
|
||||
return std::unique_ptr<T>(new U[size]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP
|
||||
#define BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/smart_ptr/detail/up_if_not_array.hpp>
|
||||
#include <boost/type_traits/add_rvalue_reference.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace boost {
|
||||
template<class T>
|
||||
inline typename boost::detail::up_if_not_array<T>::type
|
||||
make_unique() {
|
||||
return std::unique_ptr<T>(new T());
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class T, class... Args>
|
||||
inline typename boost::detail::up_if_not_array<T>::type
|
||||
make_unique(Args&&... args) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::up_if_not_array<T>::type
|
||||
make_unique(typename add_rvalue_reference<T>::type value) {
|
||||
return std::unique_ptr<T>(new T(std::move(value)));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline typename boost::detail::up_if_not_array<T>::type
|
||||
make_unique_noinit() {
|
||||
return std::unique_ptr<T>(new T);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -5,6 +5,7 @@
|
||||
// owner_less.hpp
|
||||
//
|
||||
// Copyright (c) 2008 Frank Mori Hess
|
||||
// Copyright (c) 2016 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -13,44 +14,20 @@
|
||||
// See http://www.boost.org/libs/smart_ptr/smart_ptr.htm for documentation.
|
||||
//
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<typename T> class shared_ptr;
|
||||
template<typename T> class weak_ptr;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename T, typename U>
|
||||
struct generic_owner_less : public std::binary_function<T, T, bool>
|
||||
template<class T = void> struct owner_less
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
|
||||
template<class U, class V> bool operator()( U const & u, V const & v ) const
|
||||
{
|
||||
bool operator()(const T &lhs, const T &rhs) const
|
||||
{
|
||||
return lhs.owner_before(rhs);
|
||||
}
|
||||
bool operator()(const T &lhs, const U &rhs) const
|
||||
{
|
||||
return lhs.owner_before(rhs);
|
||||
}
|
||||
bool operator()(const U &lhs, const T &rhs) const
|
||||
{
|
||||
return lhs.owner_before(rhs);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template<typename T> struct owner_less;
|
||||
|
||||
template<typename T>
|
||||
struct owner_less<shared_ptr<T> >:
|
||||
public detail::generic_owner_less<shared_ptr<T>, weak_ptr<T> >
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
struct owner_less<weak_ptr<T> >:
|
||||
public detail::generic_owner_less<weak_ptr<T>, shared_ptr<T> >
|
||||
{};
|
||||
return u.owner_before( v );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/checked_delete.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
|
||||
typedef T element_type;
|
||||
|
||||
explicit scoped_array( T * p = 0 ) BOOST_NOEXCEPT : px( p )
|
||||
explicit scoped_array( T * p = 0 ) BOOST_SP_NOEXCEPT : px( p )
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_array_constructor_hook( px );
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <boost/checked_delete.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#ifndef BOOST_NO_AUTO_PTR
|
||||
@@ -62,7 +63,7 @@ public:
|
||||
|
||||
typedef T element_type;
|
||||
|
||||
explicit scoped_ptr( T * p = 0 ): px( p ) // never throws
|
||||
explicit scoped_ptr( T * p = 0 ) BOOST_SP_NOEXCEPT : px( p ) // never throws
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_scalar_constructor_hook( px );
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/shared_count.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <cstddef> // for std::ptrdiff_t
|
||||
@@ -53,13 +54,13 @@ public:
|
||||
|
||||
typedef T element_type;
|
||||
|
||||
shared_array() BOOST_NOEXCEPT : px( 0 ), pn()
|
||||
shared_array() BOOST_SP_NOEXCEPT : px( 0 ), pn()
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
shared_array( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn()
|
||||
shared_array( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -95,11 +96,11 @@ public:
|
||||
|
||||
// ... except in C++0x, move disables the implicit copy
|
||||
|
||||
shared_array( shared_array const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
|
||||
shared_array( shared_array const & r ) BOOST_SP_NOEXCEPT : px( r.px ), pn( r.pn )
|
||||
{
|
||||
}
|
||||
|
||||
shared_array( shared_array && r ) BOOST_NOEXCEPT : px( r.px ), pn()
|
||||
shared_array( shared_array && r ) BOOST_SP_NOEXCEPT : px( r.px ), pn()
|
||||
{
|
||||
pn.swap( r.pn );
|
||||
r.px = 0;
|
||||
@@ -133,7 +134,7 @@ public:
|
||||
|
||||
// assignment
|
||||
|
||||
shared_array & operator=( shared_array const & r ) BOOST_NOEXCEPT
|
||||
shared_array & operator=( shared_array const & r ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type( r ).swap( *this );
|
||||
return *this;
|
||||
@@ -152,7 +153,7 @@ public:
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
shared_array & operator=( shared_array && r ) BOOST_NOEXCEPT
|
||||
shared_array & operator=( shared_array && r ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type( static_cast< shared_array && >( r ) ).swap( *this );
|
||||
return *this;
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <boost/smart_ptr/detail/sp_convertible.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
|
||||
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
|
||||
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
|
||||
@@ -344,13 +345,13 @@ public:
|
||||
|
||||
typedef typename boost::detail::sp_element< T >::type element_type;
|
||||
|
||||
shared_ptr() BOOST_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
|
||||
shared_ptr() BOOST_SP_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
shared_ptr( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() // never throws
|
||||
shared_ptr( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn() // never throws
|
||||
{
|
||||
}
|
||||
|
||||
@@ -402,7 +403,7 @@ public:
|
||||
|
||||
// ... except in C++0x, move disables the implicit copy
|
||||
|
||||
shared_ptr( shared_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
|
||||
shared_ptr( shared_ptr const & r ) BOOST_SP_NOEXCEPT : px( r.px ), pn( r.pn )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -521,7 +522,7 @@ public:
|
||||
|
||||
// assignment
|
||||
|
||||
shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
|
||||
shared_ptr & operator=( shared_ptr const & r ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type(r).swap(*this);
|
||||
return *this;
|
||||
@@ -605,7 +606,7 @@ public:
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
shared_ptr( shared_ptr && r ) BOOST_NOEXCEPT : px( r.px ), pn()
|
||||
shared_ptr( shared_ptr && r ) BOOST_SP_NOEXCEPT : px( r.px ), pn()
|
||||
{
|
||||
pn.swap( r.pn );
|
||||
r.px = 0;
|
||||
@@ -629,7 +630,7 @@ public:
|
||||
r.px = 0;
|
||||
}
|
||||
|
||||
shared_ptr & operator=( shared_ptr && r ) BOOST_NOEXCEPT
|
||||
shared_ptr & operator=( shared_ptr && r ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
|
||||
return *this;
|
||||
@@ -642,6 +643,14 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
// aliasing move
|
||||
template<class Y>
|
||||
shared_ptr( shared_ptr<Y> && r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn()
|
||||
{
|
||||
pn.swap( r.pn );
|
||||
r.px = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
@@ -679,7 +688,16 @@ public:
|
||||
{
|
||||
this_type( r, p ).swap( *this );
|
||||
}
|
||||
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class Y> void reset( shared_ptr<Y> && r, element_type * p )
|
||||
{
|
||||
this_type( static_cast< shared_ptr<Y> && >( r ), p ).swap( *this );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
|
||||
typename boost::detail::sp_dereference< T >::type operator* () const
|
||||
{
|
||||
@@ -865,6 +883,50 @@ template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U>
|
||||
return shared_ptr<T>( r, p );
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class T, class U> shared_ptr<T> static_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) static_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename shared_ptr<T>::element_type E;
|
||||
|
||||
E * p = static_cast< E* >( r.get() );
|
||||
return shared_ptr<T>( std::move(r), p );
|
||||
}
|
||||
|
||||
template<class T, class U> shared_ptr<T> const_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) const_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename shared_ptr<T>::element_type E;
|
||||
|
||||
E * p = const_cast< E* >( r.get() );
|
||||
return shared_ptr<T>( std::move(r), p );
|
||||
}
|
||||
|
||||
template<class T, class U> shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename shared_ptr<T>::element_type E;
|
||||
|
||||
E * p = dynamic_cast< E* >( r.get() );
|
||||
return p? shared_ptr<T>( std::move(r), p ): shared_ptr<T>();
|
||||
}
|
||||
|
||||
template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
|
||||
{
|
||||
(void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
|
||||
|
||||
typedef typename shared_ptr<T>::element_type E;
|
||||
|
||||
E * p = reinterpret_cast< E* >( r.get() );
|
||||
return shared_ptr<T>( std::move(r), p );
|
||||
}
|
||||
|
||||
#endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
// get_pointer() enables boost::mem_fn to recognize shared_ptr
|
||||
|
||||
template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
|
||||
@@ -1065,7 +1127,7 @@ template< class T > struct hash;
|
||||
|
||||
template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::hash< T* >()( p.get() );
|
||||
return boost::hash< typename boost::shared_ptr<T>::element_type* >()( p.get() );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <memory> // boost.TR1 include order fix
|
||||
#include <boost/smart_ptr/detail/shared_count.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
|
||||
typedef typename boost::detail::sp_element< T >::type element_type;
|
||||
|
||||
weak_ptr() BOOST_NOEXCEPT : px(0), pn() // never throws in 1.30+
|
||||
weak_ptr() BOOST_SP_NOEXCEPT : px(0), pn() // never throws in 1.30+
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,11 +42,11 @@ public:
|
||||
|
||||
// ... except in C++0x, move disables the implicit copy
|
||||
|
||||
weak_ptr( weak_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
|
||||
weak_ptr( weak_ptr const & r ) BOOST_SP_NOEXCEPT : px( r.px ), pn( r.pn )
|
||||
{
|
||||
}
|
||||
|
||||
weak_ptr & operator=( weak_ptr const & r ) BOOST_NOEXCEPT
|
||||
weak_ptr & operator=( weak_ptr const & r ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
px = r.px;
|
||||
pn = r.pn;
|
||||
@@ -106,13 +107,13 @@ public:
|
||||
|
||||
// for better efficiency in the T == Y case
|
||||
weak_ptr( weak_ptr && r )
|
||||
BOOST_NOEXCEPT : px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) )
|
||||
BOOST_SP_NOEXCEPT : px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) )
|
||||
{
|
||||
r.px = 0;
|
||||
}
|
||||
|
||||
// for better efficiency in the T == Y case
|
||||
weak_ptr & operator=( weak_ptr && r ) BOOST_NOEXCEPT
|
||||
weak_ptr & operator=( weak_ptr && r ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type( static_cast< weak_ptr && >( r ) ).swap( *this );
|
||||
return *this;
|
||||
|
@@ -1,273 +1,393 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>make_shared and allocate_shared for arrays</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
||||
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
||||
width="277" align="middle" border="0">make_shared and allocate_shared
|
||||
for arrays</h1>
|
||||
<p><a href="#introduction">Introduction</a><br>
|
||||
<a href="#synopsis">Synopsis</a><br>
|
||||
<a href="#common">Common Requirements</a><br>
|
||||
<a href="#functions">Free Functions</a><br>
|
||||
<a href="#history">History</a><br>
|
||||
<a href="#references">References</a></p>
|
||||
<h2><a name="introduction">Introduction</a></h2>
|
||||
<p>Originally the Boost function templates <code>make_shared</code> and
|
||||
<code>allocate_shared</code> were for efficient allocation of shared
|
||||
objects only. There was a need to have efficient allocation of
|
||||
shared arrays. One criticism of class template <code>shared_array</code>
|
||||
was always the lack of a <a href="make_shared.html">make_shared</a>
|
||||
utility which ensures only a single allocation.</p>
|
||||
<p>The header files <boost/smart_ptr/make_shared_array.hpp> and
|
||||
<boost/smart_ptr/allocate_shared_array.hpp> provide function
|
||||
templates, overloads of <code>make_shared</code> and
|
||||
<code>allocate_shared</code> for array types, to address this need.
|
||||
<code>make_shared</code> uses the global operator <code>new</code> to
|
||||
allocate memory, whereas <code>allocate_shared</code> uses an
|
||||
user-supplied allocator, allowing finer control.</p>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
<pre>namespace boost {
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size);
|
||||
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size);
|
||||
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>();
|
||||
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator);
|
||||
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size, const T& value);
|
||||
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, const T& value);
|
||||
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(const T& value);
|
||||
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, const T& value);
|
||||
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared_noinit</a>(size_t size);
|
||||
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared_noinit</a>(const A& allocator, size_t size);
|
||||
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared_noinit</a>();
|
||||
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared_noinit</a>(const A& allocator);
|
||||
}</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(<em>args</em>);
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, <em>args</em>);
|
||||
template<class U>
|
||||
shared_ptr<U> make_shared_noinit(<em>args</em>);
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, <em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> <code>U</code> is of the form <code>T[]</code> or
|
||||
<code>T[N]</code>. <code>A</code> shall be an <em>Allocator</em>, as
|
||||
described in section 17.6.3.5 [<strong>Allocator
|
||||
requirements</strong>] of the C++ Standard. The copy constructor and
|
||||
destructor of <code>A</code> shall not throw exceptions.</p>
|
||||
<p><b>Effects:</b> Allocates memory for an object of type <code>U</code>
|
||||
(or <code>T[size]</code> when <code>U</code> is <code>T[]</code>,
|
||||
where <code>size</code> is determined from <code><em>args</em></code>
|
||||
as specified by the concrete overload). The object is initialized as
|
||||
specified by the concrete overload. The templates
|
||||
<code>allocate_shared</code> and <code>allocate_shared_noinit</code>
|
||||
use a copy of <code>allocator</code> to allocate memory. If an
|
||||
exception is thrown, the functions have no effect.</p>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> instance that stores and
|
||||
owns the address of the newly constructed object.</p>
|
||||
<p><b>Postconditions:</b> <code>r.get() != 0 &&
|
||||
r.use_count() == 1</code>, where <code>r</code> is the return
|
||||
value.</p>
|
||||
<p><b>Throws:</b> <code>bad_alloc</code>, an exception thrown from
|
||||
<code>A::allocate</code>, or from the initialization of the
|
||||
object.</p>
|
||||
<p><b>Remarks:</b></p>
|
||||
<blockquote>
|
||||
<p>This implementation performs no more than one memory
|
||||
allocation. This provides efficiency to equivalent to an intrusive
|
||||
smart pointer.</p>
|
||||
<p>When an object of an array type <code>T</code> is specified to be
|
||||
initialized to a value of the same type <code>value</code>, this
|
||||
shall be interpreted to mean that each array element of the object
|
||||
is initialized to the corresponding element from
|
||||
<code>value</code>.</p>
|
||||
<p>When an object of an array type is specified to be
|
||||
value-initialized, this shall be interpreted to mean that each
|
||||
array element of the object is value-initialized.</p>
|
||||
<p>Array elements are initialized in ascending order of their
|
||||
addresses.</p>
|
||||
<p>When a subobject of a non-array type <code>T</code> is specified to
|
||||
be initialized to a value <code>value</code>,
|
||||
<code>make_shared</code> shall perform this initialization via the
|
||||
expression <code>::new(ptr) T(value)</code>, where <code>ptr</code>
|
||||
has type <code>void*</code> and points to storage suitable to hold
|
||||
an object of type <code>T</code>.</p>
|
||||
<p>When a subobject of non-array type <code>T</code> is specified to
|
||||
be initialized to a value <code>value</code>,
|
||||
<code>allocate_shared</code> shall perform this initialization via
|
||||
the expression <code>allocator_traits<A2>::construct(a2, ptr,
|
||||
value)</code>, where <code>ptr</code> points to storage suitable to
|
||||
hold an object of type <code>T</code> and <code>a2</code> of type A2
|
||||
is a rebound copy of the allocator <code>allocator</code> passed to
|
||||
<code>allocate_shared</code> such that its <code>value_type</code>
|
||||
is <code>T</code>.</p>
|
||||
<p>When a subobject of non-array type <code>T</code> is specified to
|
||||
be value-initialized, <code>make_shared</code> shall perform this
|
||||
initialization via the expression <code>::new(ptr) T()</code>, where
|
||||
<code>ptr</code> has type <code>void*</code> and points to storage
|
||||
suitable to hold an object of type <code>T</code>.</p>
|
||||
<p>When a subobject of non-array type <code>T</code> is specified to
|
||||
be value-initialized, <code>allocate_shared</code> shall perform
|
||||
this initialization via the expression
|
||||
<code>allocator_traits<A2>::construct(a2, ptr)</code>, where
|
||||
<code>ptr</code> points to storage suitable to hold an object
|
||||
of type <code>T</code> and <code>a2</code> of type A2 is a rebound
|
||||
copy of the allocator <code>allocator</code> passed to
|
||||
<code>allocate_shared</code> such that its <code>value_type</code>
|
||||
is <code>T</code>.</p>
|
||||
<p>When a subobject of non-array type <code>T</code> is specified to
|
||||
be default-initialized, <code>make_shared_noinit</code> and
|
||||
<code>allocate_shared_noinit</code> shall perform this
|
||||
initialization via the expression <code>::new(ptr) T</code>, where
|
||||
<code>ptr</code> has type <code>void*</code> and points to storage
|
||||
suitable to hold an object of type <code>T</code>.</p>
|
||||
<p>When the lifetime of the object managed by the return value ends,
|
||||
or when the initialization of an array element throws an exception,
|
||||
the initialized elements should be destroyed in the reverse order
|
||||
of their construction.</p>
|
||||
</blockquote>
|
||||
<p><b>Notes:</b> These functions will typically allocate more memory
|
||||
than <code>sizeof(U)</code> to allow for internal bookkeeping
|
||||
structures such as the reference counts.</p>
|
||||
</blockquote>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(size_t size);
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a value-initialized
|
||||
object of type <code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size);
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared();
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a value-initialized
|
||||
object of type <code>T[N]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[N]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>();
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(size_t size, const T& value);
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to an object of type
|
||||
<code>T[size]</code>, where each array element of type <code>T</code>
|
||||
is initialized to <code>value</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size, 1);
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size, {1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(const T& value);
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, const T& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to an object of type
|
||||
<code>T[N]</code>, where each array element of type <code>T</code> is
|
||||
initialized to <code>value</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[N]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>(1);
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>({1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared_noinit(size_t size);
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a default-initialized
|
||||
object of type <code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(size);
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared_noinit<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared_noinit();
|
||||
template<class U, class A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a default-initialized
|
||||
object of type <code>T[N]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[N]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared_noinit<int[8]>();
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared_noinit<int[4][2]>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<h2><a name="history">History</a></h2>
|
||||
<p>February 2014. Glen Fernandes updated overloads of make_shared and
|
||||
allocate_shared to conform to the specification in C++ standard paper
|
||||
<a href="#N3870">N3870</a>, including resolving C++ standard library
|
||||
defect report 2070, and reduced the spatial overhead of the internal
|
||||
bookkeeping structures.</p>
|
||||
<p>November 2012. Glen Fernandes contributed implementations of
|
||||
make_shared and allocate_shared for arrays.</p>
|
||||
<h2><a name="references">References</a></h2>
|
||||
<p><a name="N3870">N3870</a>,
|
||||
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3870.html">
|
||||
Extending make_shared to Support Arrays, Revision 1</a>, Peter Dimov
|
||||
& Glen Fernandes, January, 2014.</p>
|
||||
<hr>
|
||||
<p>$Date$</p>
|
||||
<p><small>Copyright 2012-2014 Glen Fernandes. Distributed under the
|
||||
Boost Software License, Version 1.0. See accompanying file
|
||||
<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt</a>.</small></p>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>allocate_shared and make_shared for arrays</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>allocate_shared and make_shared for arrays</h1>
|
||||
<div id="navigation">
|
||||
<ul>
|
||||
<li><a href="#introduction">Introduction</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#requirements">Common Requirements</a></li>
|
||||
<li><a href="#functions">Free Functions</a></li>
|
||||
<li><a href="#history">History</a></li>
|
||||
<li><a href="#references">References</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="introduction">
|
||||
<h2>Introduction</h2>
|
||||
<p>
|
||||
Originally the Boost function templates <code>allocate_shared</code> and
|
||||
<code>make_shared</code> were for efficient allocation of shared scalar
|
||||
objects only. There was a need to have efficient allocation of shared
|
||||
arrays. One criticism of class template <code>shared_array</code>
|
||||
was always the lack of a utility like <code>make_shared</code> that
|
||||
uses only a single allocation.
|
||||
</p>
|
||||
<p>
|
||||
The header files <boost/smart_ptr/allocate_shared_array.hpp> and
|
||||
<boost/smart_ptr/make_shared_array.hpp> provide function
|
||||
templates, overloads of <code>allocate_shared</code> and
|
||||
<code>make_shared</code> for array types, to address this need.
|
||||
<code>allocate_shared</code> uses a user-supplied allocator for
|
||||
allocation, while <code>make_shared</code> uses
|
||||
<code>allocate_shared</code> with the Default Allocator.
|
||||
</p>
|
||||
</div>
|
||||
<div id="synopsis">
|
||||
<h2>Synopsis</h2>
|
||||
<div>
|
||||
<h3>Header <boost/smart_ptr/allocate_shared_array.hpp></h3>
|
||||
<code>namespace boost {</code>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a,
|
||||
std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a, std::size_t n,
|
||||
const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a,
|
||||
const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared_noinit</a>(const A& a,
|
||||
std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared_noinit</a>(const A& a);</code>
|
||||
</blockquote>
|
||||
<code>}</code>
|
||||
</div>
|
||||
<div>
|
||||
<h3>Header <boost/smart_ptr/make_shared_array.hpp></h3>
|
||||
<code>namespace boost {</code>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>(std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>();</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>(std::size_t n,
|
||||
const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>(const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared_noinit</a>(std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared_noinit</a>();</code>
|
||||
</blockquote>
|
||||
<code>}</code>
|
||||
</div>
|
||||
</div>
|
||||
<div id="requirements">
|
||||
<h2>Common Requirements</h2>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a, <em>args</em>);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Requires:</strong></dt>
|
||||
<dd><code>T</code> is of the form <code>E[N]</code> or
|
||||
<code>E[]</code>. <code>A</code> shall be an <em>Allocator</em>, as
|
||||
described in section 17.6.3.5 [Allocator requirements] of the C++
|
||||
Standard. The copy constructor and destructor of <code>A</code> shall
|
||||
not throw exceptions.</dd>
|
||||
<dt><strong>Effects:</strong></dt>
|
||||
<dd>Allocates storage for an object of type <code>E</code> (or
|
||||
<code>E[size]</code> when <code>T</code> is <code>E[]</code>, where
|
||||
<code>size</code> is determined from <code>args</code> as specified by
|
||||
the concrete overload). A copy of the allocator is used to allocate
|
||||
storage. The storage is initialized as specified by the concrete
|
||||
overload. If an exception is thrown, the functions have no effect.</dd>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> instance that stores and owns the address
|
||||
of the newly allocated and constructed object.</dd>
|
||||
<dt><strong>Postconditions:</strong></dt>
|
||||
<dd><code>r.get() != 0</code> and <code>r.use_count() == 1</code>,
|
||||
where <code>r</code> is the return value.</dd>
|
||||
<dt><strong>Throws:</strong></dt>
|
||||
<dd>An exception thrown from <code>A::allocate()</code>, or from the
|
||||
initialization of the object.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>This implementation performs no more than one memory allocation.
|
||||
This provides efficiency to equivalent to an intrusive smart
|
||||
pointer.</li>
|
||||
<li>When an object of an array type <code>T</code> is specified to be
|
||||
initialized to a value of the same type <code>v</code>, this shall be
|
||||
interpreted to mean that each array element of the object is initialized
|
||||
to the corresponding element from <code>v</code>.</li>
|
||||
<li>When an object of an array type <code>T</code> is specified to be
|
||||
value-initialized, this shall be interpreted to mean that each array
|
||||
element of the object is value-initialized.</li>
|
||||
<li>Array elements are initialized in ascending order of their
|
||||
addresses.</li>
|
||||
<li>When a subobject of a scalar type <code>S</code> is specified to
|
||||
be initialized to a value <code>v</code>, <code>allocate_shared</code>
|
||||
shall perform this initialization via the expression
|
||||
<code>std::allocator_traits<A>::construct(b, p, v)</code>, where
|
||||
<code>p</code> points to storage suitable to hold an object of type
|
||||
<code>S</code> and <code>b</code> of is a copy of the allocator
|
||||
<code>a</code> passed to <code>allocate_shared</code> such that its
|
||||
<code>value_type</code> is <code>S</code>.</li>
|
||||
<li>When a subobject of scalar type <code>S</code> is specified to be
|
||||
value-initialized, <code>allocate_shared</code> shall perform this
|
||||
initialization via the expression
|
||||
<code>std::allocator_traits<A>::construct(b, p)</code>, where
|
||||
<code>p</code> points to storage suitable to hold an object
|
||||
of type <code>S</code> and <code>b</code> is a copy of the allocator
|
||||
<code>a</code> passed to <code>allocate_shared</code> such that its
|
||||
<code>value_type</code> is <code>S</code>.</li>
|
||||
<li>When a subobject of scalar type <code>S</code> is specified to be
|
||||
default-initialized, <code>allocate_shared_noinit</code> shall perform
|
||||
this initialization via the expression <code>::new(p) S</code>, where
|
||||
<code>p</code> has type <code>void*</code> and points to storage
|
||||
suitable to hold an object of type <code>S</code>.</li>
|
||||
<li>When the lifetime of the object managed by the return value ends,
|
||||
or when the initialization of an array element throws an exception,
|
||||
the initialized elements should be destroyed in the reverse order
|
||||
of their construction.</li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt><strong>Notes:</strong></dt>
|
||||
<dd>These functions will typically allocate more memory than the size of
|
||||
<code>sizeof(E)</code> to allow for internal bookkeeping structures such
|
||||
as the reference counts.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div id="functions">
|
||||
<h2>Free Functions</h2>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a, std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a value-initialized object of type
|
||||
<code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::allocate_shared<int[]<!--
|
||||
-->>(std::allocator<int>(), 8);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a value-initialized object of type
|
||||
<code>E[N]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::allocate_shared<int[8]<!--
|
||||
-->>(std::allocator<int>());</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a, std::size_t n,
|
||||
const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to an object of type
|
||||
<code>E[size]</code>, where each array element of type <code>E</code> is
|
||||
initialized to <code>v</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::allocate_shared<double[]<!--
|
||||
-->>(std::allocator<double>(), 8, 1.0);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a, const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to an object of type <code>E[N]</code>,
|
||||
where each array element of type <code>E</code> is initialized to
|
||||
<code>v</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::allocate_shared<double[8]<!--
|
||||
-->>(std::allocator<double>(), 1.0);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared_noinit(const A& a, std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a default-initialized object of type
|
||||
<code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::allocate_shared_noinit<int[]<!--
|
||||
-->>(std::allocator<int>(), 8);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared_noinit(const A& a);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a default-initialized object of type
|
||||
<code>E[N]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::allocate_shared_noinit<int[8]<!--
|
||||
-->>(std::allocator<int>());</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared(std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), n);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_shared<int[]>(8);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared();</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>());</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_shared<int[8]>();</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared(std::size_t n, const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), n, v);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_shared<double[]>(8, 1.0);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared(const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), v);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N].</code></dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_shared<double[8]>(1.0);</code></dd></dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared_noinit(std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared_noinit<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), n);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_shared_noinit<int[]>(8);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared_noinit();</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared_noinit<T>(std::allocator<<em>S<!--
|
||||
--></em>>());</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_shared_noinit<int[8]>();</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div id="history">
|
||||
<h2>History</h2>
|
||||
<dl>
|
||||
<dt><strong>Boost 1.64</strong></dt>
|
||||
<dd>Glen Fernandes rewrote allocate_shared and make_shared for a more
|
||||
optimal and more maintainable implementation.</dd>
|
||||
<dt><strong>Boost 1.56</strong></dt>
|
||||
<dd>Glen Fernandes updated overloads of make_shared and allocate_shared
|
||||
to conform to the specification in C++ standard paper
|
||||
<a href="#N3870">N3870</a>, including resolving C++ standard library
|
||||
defect report <a href="#dr2070">DR 2070</a>.</dd>
|
||||
<dt><strong>Boost 1.53</strong></dt>
|
||||
<dd>Glen Fernandes contributed implementations of make_shared and
|
||||
allocate_shared for arrays.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div id="references">
|
||||
<h2>References</h2>
|
||||
<ol>
|
||||
<li id="N3870"><strong>N3870</strong>, <a href=
|
||||
"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3870.html">
|
||||
Extending make_shared to Support Arrays, Revision 1</a>, Peter Dimov
|
||||
& Glen Fernandes, January, 2014.</li>
|
||||
<li id="dr2070"><strong>DR 2070</strong>,
|
||||
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html">
|
||||
allocate_shared should use allocator_traits<A>::construct</a>,
|
||||
Jonathan Wakely, July, 2011.</li>
|
||||
</ol>
|
||||
</div>
|
||||
<hr>
|
||||
Copyright 2012-2017 Glen Fernandes. Distributed under the
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License,
|
||||
Version 1.0</a>.
|
||||
</body>
|
||||
</html>
|
||||
|
334
make_unique.html
334
make_unique.html
@@ -1,152 +1,184 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>make_unique</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
||||
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
||||
width="277" align="middle" border="0">make_unique</h1>
|
||||
<p><a href="#introduction">Introduction</a><br>
|
||||
<a href="#synopsis">Synopsis</a><br>
|
||||
<a href="#common">Common Requirements</a><br>
|
||||
<a href="#functions">Free Functions</a><br>
|
||||
<a href="#history">History</a></p>
|
||||
<h2><a name="introduction">Introduction</a></h2>
|
||||
<p>The header file <boost/make_unique.hpp> provides overloaded
|
||||
function template <code>make_unique</code> for convenient creation of
|
||||
<code>unique_ptr</code> objects.</p>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
<pre>namespace boost {
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>();
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class U, class... Args> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(Args&&... args);
|
||||
#endif
|
||||
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(U&& value);
|
||||
|
||||
template<class U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(size_t size);
|
||||
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>();
|
||||
|
||||
template<class U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>(size_t size);
|
||||
}</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(<em>args</em>);
|
||||
template<class U>
|
||||
unique_ptr<U> make_unique_noinit(<em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<p><b>Effects:</b> Allocates memory for an object of type <code>U</code>
|
||||
(or <code>T[size]</code> when <code>U</code> is <code>T[]</code>,
|
||||
where <code>size</code> is determined from <code>args</code> as
|
||||
specified by the concrete overload). The object is initialized from
|
||||
<code>args</code> as specified by the concrete overload. If an
|
||||
exception is thrown, the functions have no effect.</p>
|
||||
<p><b>Returns:</b> A <code>unique_ptr</code> instance that stores and
|
||||
owns the address of the newly constructed object.</p>
|
||||
<p><b>Postconditions:</b> <code>r.get() != 0</code>, where
|
||||
<code>r</code> is the return value.</p>
|
||||
<p><b>Throws:</b> <code>bad_alloc</code>, or an exception thrown from
|
||||
the initialization of the object.</p>
|
||||
<p><b>Remarks:</b></p>
|
||||
<blockquote>
|
||||
<p>When an object of a non-array type <code>T</code> is specified to
|
||||
be initialized to a value <code>value</code>, or to
|
||||
<code>T(list...)</code>, where <code>list...</code> is a list of
|
||||
constructor arguments, <code>make_unique</code> shall perform this
|
||||
initialization via the expression <code>new T(value)</code> or
|
||||
<code>new T(list...)</code> respectively.</p>
|
||||
<p>When an object of type <code>T</code> is specified to be
|
||||
value-initialized, <code>make_unique</code> shall perform this
|
||||
initialization via the expression <code>new T()</code>.</p>
|
||||
<p>When an object of type <code>T</code> is specified to be
|
||||
default-initialized, <code>make_unique_noinit</code> shall perform
|
||||
this initialization via the expression <code>new T</code>.</p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<class U, class... Args>
|
||||
unique_ptr<U> make_unique(Args&&... args);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to an object of type <code>U</code>,
|
||||
initialized to <code>U(forward<Args>(args)...)</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is not an array type.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique<float>();
|
||||
unique_ptr<point> p2 = boost::make_unique<point>(x, y);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(U&& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to an object of type <code>U</code>,
|
||||
initialized to <code>move(value)</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is not an array type.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<string> p1 = boost::make_unique<string>({'a', 'b'});
|
||||
unique_ptr<point> p2 = boost::make_unique<point>({-10, 25});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to a value-initialized object of type
|
||||
<code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> p1 = boost::make_unique<double[]>(4);
|
||||
unique_ptr<int[][2]> p2 = boost::make_unique<int[][2]>(2);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique_noinit();</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to a default-initialized object of
|
||||
type <code>U</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is not an array type.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique_noinit<float>();
|
||||
unique_ptr<point> p2 = boost::make_unique_noinit<point>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique_noinit(size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to a default-initialized object of
|
||||
type <code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> p1 = boost::make_unique_noinit<double[]>(4);
|
||||
unique_ptr<int[][2]> p2 = boost::make_unique_noinit<int[][2]>(2);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<h2><a name="history">History</a></h2>
|
||||
<p>January 2014. Glen Fernandes contributed implementations of
|
||||
make_unique for objects and arrays.</p>
|
||||
<hr>
|
||||
<p>$Date$</p>
|
||||
<p><small>Copyright 2012-2014 Glen Fernandes. Distributed under the
|
||||
Boost Software License, Version 1.0. See accompanying file
|
||||
<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt</a>.</small></p>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>make_unique</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>make_unique</h1>
|
||||
<div id="navigation">
|
||||
<ul>
|
||||
<li><a href="#introduction">Introduction</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#requirements">Common Requirements</a></li>
|
||||
<li><a href="#functions">Free Functions</a></li>
|
||||
<li><a href="#history">History</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="introduction">
|
||||
<h2>Introduction</h2>
|
||||
<p>
|
||||
The header file <boost/make_unique.hpp> provides overloads of
|
||||
function template <code>make_unique</code> for convenient creation of
|
||||
<code>std::unique_ptr</code> objects.
|
||||
</p>
|
||||
</div>
|
||||
<div id="synopsis">
|
||||
<h2>Synopsis</h2>
|
||||
<div>
|
||||
<h3>Header <boost/smart_ptr/make_unique.hpp></h3>
|
||||
<code>namespace boost {</code>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>();</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class... Args><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>(Args&&... args);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>(<em>T</em>&& value);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>(std::size_t size);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique_noinit</a>();</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique_noinit</a>(std::size_t size);</code>
|
||||
</blockquote>
|
||||
<code>}</code>
|
||||
</div>
|
||||
</div>
|
||||
<div id="requirements">
|
||||
<h2>Common Requirements</h2>
|
||||
<h3><code>template<class T, <em>Args</em>><br>
|
||||
std::unique_ptr<T> make_unique(<em>args</em>);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Effects:</strong></dt>
|
||||
<dd>Allocates storage for an object of type <code>T</code> (or
|
||||
<code>E[size]</code> when <code>T</code> is <code>E[]</code>, where
|
||||
<code>size</code> is determined from <code>args</code> as specified by
|
||||
the concrete overload). The storage is initialized from
|
||||
<code>args</code> as specified by the concrete overload. If an exception
|
||||
is thrown, the functions have no effect.</dd>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> instance that stores and owns the
|
||||
address of the newly allocated and constructed object.</dd>
|
||||
<dt><strong>Postconditions:</strong></dt>
|
||||
<dd><code>r.get() != 0</code>, where <code>r</code> is the return
|
||||
value.</dd>
|
||||
<dt><strong>Throws:</strong></dt>
|
||||
<dd><code>std::bad_alloc</code>, or an exception thrown from the
|
||||
initialization of the object.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>When an object of a scalar type T is specified to be initialized to
|
||||
a value <code>value</code>, or to <code>T(args...)</code>, where
|
||||
<code>args...</code> is a list of constructor arguments,
|
||||
<code>make_unique</code> shall perform this initialization via the
|
||||
expression <code>new T(value)</code> or <code>new T(args...)</code>
|
||||
respectively.</li>
|
||||
<li>When an object of type <code>T</code> is specified to be
|
||||
value-initialized, <code>make_unique</code> shall perform this
|
||||
initialization via the expression <code>new T()</code>.</li>
|
||||
<li>When an object of type <code>T</code> is specified to be
|
||||
default-initialized, <code>make_unique_noinit</code> shall perform this
|
||||
initialization via the expression <code>new T</code>.</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div id="functions">
|
||||
<h2>Free functions</h2>
|
||||
<div>
|
||||
<h3><code>template<class T, class... Args><br>
|
||||
std::unique_ptr<T>
|
||||
make_unique(Args&&... args);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to an object of type <code>T</code>,
|
||||
initialized to <code>std::forward<Args>(args)...</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is not an array type.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_unique<double>(1.0);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique(<em>T</em>&& value);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to an object of type <code>T</code>,
|
||||
initialized to <code>std::move(value)</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is not an array type.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_unique<point>({1.0, -1.0});</code></dd></dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique(std::size_t size);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to a value-initialized object of type
|
||||
<code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_unique<int[]>(8);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique_noinit();</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to a default-initialized object of
|
||||
type <code>T</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is not an array type.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_unique_noinit<std::tm>();</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique_noinit(std::size_t size);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to a default-initialized object of
|
||||
type <code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
<dt><strong>Example:</strong></dt>
|
||||
<dd><code>boost::make_unique_noinit<char[]>(64);</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div id="history">
|
||||
<h2>History</h2>
|
||||
<dl>
|
||||
<dt><strong>Boost 1.56</strong></dt>
|
||||
<dd>Glen Fernandes contributed implementations of make_unique for
|
||||
scalars and arrays</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<hr>
|
||||
Copyright 2012-2014 Glen Fernandes. Distributed under the
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License,
|
||||
Version 1.0</a>.
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -2,16 +2,16 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>pointer_cast</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
||||
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
||||
width="277" align="middle" border="0">pointer_cast</h1>
|
||||
width="277" align="middle" border="0" />pointer_cast</h1>
|
||||
<p>The pointer cast functions (<code>boost::static_pointer_cast</code> <code>boost::dynamic_pointer_cast</code>
|
||||
<code>boost::reinterpret_pointer_cast</code> <code>boost::const_pointer_cast</code>)
|
||||
provide a way to write generic pointer castings for raw pointers. The functions
|
||||
are defined in <CITE><A href="../../boost/pointer_cast.hpp">boost/pointer_cast.hpp</A>.</CITE></p>
|
||||
<P>There is test/example code in <CITE><A href="test/pointer_cast_test.cpp">pointer_cast_test.cpp</A></CITE>.</p>
|
||||
provide a way to write generic pointer castings for raw pointers, <code>std::shared_ptr</code> and <code>std::unique_ptr</code>. The functions
|
||||
are defined in <cite><a href="../../boost/pointer_cast.hpp">boost/pointer_cast.hpp</a>.</cite></p>
|
||||
<p>There is test/example code in <cite><a href="test/pointer_cast_test.cpp">pointer_cast_test.cpp</a></cite>.</p>
|
||||
<h2><a name="rationale">Rationale</a></h2>
|
||||
<P>Boost smart pointers usually overload those functions to provide a mechanism to
|
||||
emulate pointers casts. For example, <code>boost::shared_ptr<...></code> implements
|
||||
@@ -20,15 +20,15 @@
|
||||
template<class T, class U>
|
||||
shared_ptr<T> static_pointer_cast(shared_ptr<U> const &r);
|
||||
</pre>
|
||||
<P>Pointer cast functions from <CITE><A href="../../boost/pointer_cast.hpp">boost/pointer_cast.hpp</A></CITE>
|
||||
<p>Pointer cast functions from <cite><A href="../../boost/pointer_cast.hpp">boost/pointer_cast.hpp</A></CITE>
|
||||
are overloads of <code>boost::static_pointer_cast</code>, <code>boost::dynamic_pointer_cast</code>,
|
||||
<code>boost::reinterpret_pointer_cast</code> and <code>boost::const_pointer_cast</code>
|
||||
for raw pointers. This way when developing pointer type independent classes,
|
||||
for example, memory managers or shared memory compatible classes, the same code
|
||||
can be used for raw and smart pointers.</p>
|
||||
<H2><A name="synopsis">Synopsis</A></H2>
|
||||
<BLOCKQUOTE>
|
||||
<PRE>
|
||||
for raw pointers, <code>std::shared_ptr</code> and <code>std::unique_ptr</code>. This way when developing
|
||||
pointer type independent classes, for example, memory managers or shared memory compatible classes, the same
|
||||
code can be used for raw and smart pointers.</p>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
<blockquote>
|
||||
<pre>
|
||||
namespace boost {
|
||||
|
||||
template<class T, class U>
|
||||
@@ -46,15 +46,93 @@ inline T* const_pointer_cast(U *ptr)
|
||||
template<class T, class U>
|
||||
inline T* reinterpret_pointer_cast(U *ptr)
|
||||
{ return reinterpret_cast<T*>(ptr); }
|
||||
|
||||
template<class T, class U>
|
||||
inline std::shared_ptr<T> static_pointer_cast(std::shared_ptr<U> const& r);
|
||||
|
||||
template<class T, class U>
|
||||
inline std::shared_ptr<T> dynamic_pointer_cast(std::shared_ptr<U> const& r);
|
||||
|
||||
template<class T, class U>
|
||||
inline std::shared_ptr<T> const_pointer_cast(std::shared_ptr<U> const& r);
|
||||
|
||||
template<class T, class U>
|
||||
inline std::shared_ptr<T> reinterpret_pointer_cast(std::shared_ptr<U> const& r);
|
||||
|
||||
template<class T, class U>
|
||||
inline std::unique_ptr<T> static_pointer_cast(std::unique_ptr<U>&& r);
|
||||
|
||||
template<class T, class U>
|
||||
inline std::unique_ptr<T> dynamic_pointer_cast(std::unique_ptr<U>&& r);
|
||||
|
||||
template<class T, class U>
|
||||
inline std::unique_ptr<T> const_pointer_cast(std::unique_ptr<U>&& r);
|
||||
|
||||
template<class T, class U>
|
||||
inline std::unique_ptr<T> reinterpret_pointer_cast(std::unique_ptr<U>&& r);
|
||||
|
||||
} // namespace boost
|
||||
</PRE>
|
||||
</BLOCKQUOTE>
|
||||
<P>As you can see from the above synopsis, the pointer cast functions are just
|
||||
wrappers around standard C++ cast operators.</P>
|
||||
<H2><A name="example">Example</A></H2>
|
||||
<BLOCKQUOTE>
|
||||
<PRE>
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>As you can see from the above synopsis, the pointer cast functions for raw pointers are just
|
||||
wrappers around standard C++ cast operators.</p>
|
||||
|
||||
<p>The pointer casts for <code>std::shared_ptr</code> are aliases of the corresponding standard
|
||||
functions with the same names and equivalent to <a href="shared_ptr.htm#static_pointer_cast">the
|
||||
functions taking <code>boost::shared_ptr</code></a>.</p>
|
||||
|
||||
<p>The pointer casts for <code>std::unique_ptr</code> are documented below.</p>
|
||||
|
||||
<h3 id="static_pointer_cast">static_pointer_cast</h3>
|
||||
<pre>template<class T, class U>
|
||||
unique_ptr<T> static_pointer_cast(unique_ptr<U>&& r); // never throws</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>static_cast<T*>( (U*)0 )</code>
|
||||
must be well-formed.</p>
|
||||
<p><b>Returns:</b> <code>unique_ptr<T>( static_cast<typename unique_ptr<T>::element_type*>(r.release()) )</code>.</p>
|
||||
<p><b>Throws:</b> nothing.</p>
|
||||
<p><b>Notes:</b> the seemingly equivalent expression
|
||||
<code>unique_ptr<T>(static_cast<T*>(r.get()))</code>
|
||||
will eventually result in undefined behavior, attempting to delete the same
|
||||
object twice.</p>
|
||||
</blockquote>
|
||||
<h3 id="const_pointer_cast">const_pointer_cast</h3>
|
||||
<pre>template<class T, class U>
|
||||
unique_ptr<T> const_pointer_cast(unique_ptr<U>&& r); // never throws</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>const_cast<T*>( (U*)0 )</code>
|
||||
must be well-formed.</p>
|
||||
<p><b>Returns:</b> <code>unique_ptr<T>( const_cast<typename unique_ptr<T>::element_type*>(r.release()) )</code>.</p>
|
||||
<p><b>Throws:</b> nothing.</p>
|
||||
</blockquote>
|
||||
<h3 id="dynamic_pointer_cast">dynamic_pointer_cast</h3>
|
||||
<pre>template<class T, class U>
|
||||
unique_ptr<T> dynamic_pointer_cast(unique_ptr<U>&& r);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>dynamic_cast<T*>( (U*)0 )</code>
|
||||
must be well-formed. <code>T</code> must have a virtual destructor.</p>
|
||||
<p><b>Returns:</b></p>
|
||||
<ul>
|
||||
<li>
|
||||
When <code>dynamic_cast<typename unique_ptr<T>::element_type*>(r.get())</code> returns a nonzero value,
|
||||
<code>unique_ptr<T>(dynamic_cast<typename unique_ptr<T>::element_type*>(r.release()))</code>;</li>
|
||||
<li>
|
||||
Otherwise, <code>unique_ptr<T>()</code>.</li></ul>
|
||||
<p><b>Throws:</b> nothing.</p>
|
||||
</blockquote>
|
||||
<h3 id="reinterpret_pointer_cast">reinterpret_pointer_cast</h3>
|
||||
<pre>template<class T, class U>
|
||||
unique_ptr<T> reinterpret_pointer_cast(unique_ptr<U>&& r); // never throws</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>reinterpret_cast<T*>( (U*)0 )</code>
|
||||
must be well-formed.</p>
|
||||
<p><b>Returns:</b> <code>unique_ptr<T>( reinterpret_cast<typename unique_ptr<T>::element_type*>(r.release()) )</code>.</p>
|
||||
<p><b>Throws:</b> nothing.</p>
|
||||
</blockquote>
|
||||
|
||||
<h2><a name="example">Example</a></h2>
|
||||
<blockquote>
|
||||
<pre>
|
||||
#include <boost/pointer_cast.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
@@ -79,28 +157,27 @@ void check_if_it_is_derived(const BasePtr &ptr)
|
||||
|
||||
int main()
|
||||
{
|
||||
<I>// Create a raw and a shared_ptr</I>
|
||||
<em>// Create a raw and a shared_ptr</em>
|
||||
|
||||
base *ptr = new derived;
|
||||
boost::shared_ptr<base> sptr(new derived);
|
||||
|
||||
<I>// Check that base pointer points actually to derived class</I>
|
||||
<em>// Check that base pointer points actually to derived class</em>
|
||||
|
||||
check_if_it_is_derived(ptr);
|
||||
check_if_it_is_derived(sptr);
|
||||
|
||||
// <EM>Ok!</EM>
|
||||
<em>// Ok!</em>
|
||||
|
||||
delete ptr;
|
||||
return 0;
|
||||
}</PRE>
|
||||
</BLOCKQUOTE>
|
||||
<P>The example demonstrates how the generic pointer casts help us create pointer
|
||||
independent code.</P>
|
||||
<hr>
|
||||
<p>$Date$</p>
|
||||
}</pre>
|
||||
</blockquote>
|
||||
<p>The example demonstrates how the generic pointer casts help us create pointer
|
||||
independent code.</p>
|
||||
<hr />
|
||||
<p>Copyright 2005 Ion Gazta<74>aga. Use, modification, and distribution are subject to
|
||||
the Boost Software License, Version 1.0. (See accompanying file <A href="../../LICENSE_1_0.txt">
|
||||
LICENSE_1_0.txt</A> or a copy at <<A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>>.)</p>
|
||||
the Boost Software License, Version 1.0. (See accompanying file <a href="../../LICENSE_1_0.txt">
|
||||
LICENSE_1_0.txt</a> or a copy at <<a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -139,6 +139,8 @@ void bad()
|
||||
|
||||
template<class Y> <a href="#aliasing_constructor" >shared_ptr</a>(shared_ptr<Y> const & r, element_type * p); // never throws
|
||||
|
||||
template<class Y> <a href="#aliasing_move_constructor" >shared_ptr</a>(shared_ptr<Y> && r, element_type * p); // never throws
|
||||
|
||||
template<class Y> explicit <a href="#weak_ptr_constructor" >shared_ptr</a>(<a href="weak_ptr.htm" >weak_ptr</a><Y> const & r);
|
||||
|
||||
template<class Y> explicit <a href="#auto_ptr_constructor" >shared_ptr</a>(std::auto_ptr<Y> & r);
|
||||
@@ -220,7 +222,7 @@ void bad()
|
||||
shared_ptr<T> <a href="#dynamic_pointer_cast" >dynamic_pointer_cast</a>(shared_ptr<U> const & r); // never throws
|
||||
|
||||
template<class T, class U>
|
||||
shared_ptr<T> <a href="#reinterpret_pointer_cast" >reinterpet_pointer_cast</a>(shared_ptr<U> const & r); // never throws
|
||||
shared_ptr<T> <a href="#reinterpret_pointer_cast" >reinterpret_pointer_cast</a>(shared_ptr<U> const & r); // never throws
|
||||
|
||||
template<class E, class T, class Y>
|
||||
std::basic_ostream<E, T> & <a href="#insertion-operator" >operator<<</a> (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p);
|
||||
@@ -352,6 +354,16 @@ template<class Y> shared_ptr(shared_ptr<Y> && r); // never t
|
||||
<p><b>Postconditions:</b> <code>get() == p && use_count() == r.use_count()</code>.</p>
|
||||
<p><b>Throws:</b> nothing.</p>
|
||||
</blockquote>
|
||||
<h3 id="aliasing_move_constructor">aliasing move constructor</h3>
|
||||
<pre>template<class Y> shared_ptr(shared_ptr<Y> && r, element_type * p); // never throws</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Effects:</b> Move-constructs a <code>shared_ptr</code> from <code>r</code>, while
|
||||
storing <code>p</code> instead.
|
||||
</p>
|
||||
<p><b>Postconditions:</b> <code>get() == p</code> and <code>use_count()</code> equals the old count of <code>r</code>. <code>r</code> is <em>empty</em> and <code>r.get() == 0</code>.</p>
|
||||
<p><b>Throws:</b> nothing.</p>
|
||||
</blockquote>
|
||||
<h3 id="weak_ptr_constructor">weak_ptr constructor</h3>
|
||||
<pre>template<class Y> explicit shared_ptr(<a href="weak_ptr.htm" >weak_ptr</a><Y> const & r);</pre>
|
||||
<blockquote>
|
||||
|
@@ -136,6 +136,9 @@
|
||||
<p>Functions which destroy objects of the pointed to type are prohibited from
|
||||
throwing exceptions by the <a href="#common_requirements">common requirements</a>.</p>
|
||||
<h2><a name="History">History</a> and Acknowledgements</h2>
|
||||
<p>February 2017. Glen Fernandes rewrote <b>allocate_shared</b>
|
||||
and <b>make_shared</b> for arrays for a more optimal and more
|
||||
maintainable implementation.</p>
|
||||
<p>February 2014. Glen Fernandes updated overloads of <b>make_shared</b> and
|
||||
<b>allocate_shared</b> to conform to the specification in C++ standard paper
|
||||
<a href="#D&F-14">[D&F-14]</a>, and implemented <b>make_unique</b> for
|
||||
|
@@ -29,11 +29,15 @@ import testing ;
|
||||
[ compile-fail shared_ptr_compare_fail.cpp ]
|
||||
[ run shared_ptr_alloc2_test.cpp ]
|
||||
[ run pointer_cast_test.cpp ]
|
||||
[ run cpp11_pointer_cast_test.cpp ]
|
||||
[ compile pointer_to_other_test.cpp ]
|
||||
[ run auto_ptr_rv_test.cpp ]
|
||||
[ run shared_ptr_alias_test.cpp ]
|
||||
[ run shared_ptr_rv_test.cpp ]
|
||||
[ run shared_ptr_rv_pointer_cast_test.cpp ]
|
||||
[ run shared_ptr_move_test.cpp ]
|
||||
[ run shared_ptr_alias_move_test.cpp ]
|
||||
[ run shared_ptr_reinterpret_pointer_cast_test.cpp ]
|
||||
[ compile-fail shared_ptr_pv_fail.cpp ]
|
||||
[ run sp_unary_addr_test.cpp ]
|
||||
[ compile-fail scoped_ptr_eq_fail.cpp ]
|
||||
@@ -46,6 +50,7 @@ import testing ;
|
||||
[ run spinlock_try_test.cpp : : : <threading>multi : spinlock_try_test.mt ]
|
||||
[ run spinlock_pool_test.cpp ]
|
||||
[ run make_shared_test.cpp ]
|
||||
[ run make_shared_move_emulation_test.cpp ]
|
||||
[ run make_shared_perfect_forwarding_test.cpp ]
|
||||
[ run shared_ptr_convertible_test.cpp ]
|
||||
[ run wp_convertible_test.cpp ]
|
||||
@@ -79,6 +84,7 @@ import testing ;
|
||||
[ run sa_nullptr_test.cpp ]
|
||||
[ run shared_ptr_alloc3_test.cpp ]
|
||||
[ run shared_ptr_alloc11_test.cpp ]
|
||||
[ run shared_ptr_alloc_construct11_test.cpp ]
|
||||
[ run allocate_shared_alloc11_test.cpp ]
|
||||
[ run allocate_shared_construct11_test.cpp ]
|
||||
[ run sp_interlocked_test.cpp ]
|
||||
@@ -181,5 +187,26 @@ import testing ;
|
||||
[ run weak_from_this_test2.cpp ]
|
||||
|
||||
[ run sp_bml_unique_ptr_test.cpp ]
|
||||
|
||||
[ run sp_hash_test2.cpp ]
|
||||
[ run sp_hash_test3.cpp ]
|
||||
|
||||
[ run pointer_cast_test2.cpp ]
|
||||
|
||||
[ compile-fail pointer_cast_st_fail.cpp ]
|
||||
[ compile-fail pointer_cast_st_fail2.cpp ]
|
||||
[ compile-fail pointer_cast_st_fail3.cpp ]
|
||||
|
||||
[ compile-fail pointer_cast_co_fail.cpp ]
|
||||
[ compile-fail pointer_cast_co_fail2.cpp ]
|
||||
[ compile-fail pointer_cast_co_fail3.cpp ]
|
||||
|
||||
[ compile-fail pointer_cast_dy_fail.cpp ]
|
||||
[ compile-fail pointer_cast_dy_fail2.cpp ]
|
||||
[ compile-fail pointer_cast_dy_fail3.cpp ]
|
||||
|
||||
[ run sp_nothrow_test.cpp ]
|
||||
|
||||
[ compile make_shared_msvc_test.cpp ]
|
||||
;
|
||||
}
|
||||
|
@@ -1,160 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
template<typename T>
|
||||
class creator {
|
||||
public:
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
struct allow { };
|
||||
|
||||
template<class T>
|
||||
struct creator {
|
||||
typedef T value_type;
|
||||
|
||||
creator() {
|
||||
}
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef creator<U> other;
|
||||
};
|
||||
|
||||
template<typename U>
|
||||
creator(const creator<U>&) {
|
||||
}
|
||||
creator() { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>&) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
void* p1 = ::operator new(size * sizeof(T));
|
||||
return static_cast<T*>(p1);
|
||||
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||
}
|
||||
|
||||
void deallocate(T* memory, std::size_t) {
|
||||
void* p1 = memory;
|
||||
::operator delete(p1);
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
void construct(U* memory) {
|
||||
void* p1 = memory;
|
||||
::new(p1) U();
|
||||
template<class U>
|
||||
void construct(U* ptr) {
|
||||
::new(static_cast<void*>(ptr)) U(allow());
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
void destroy(U* memory) {
|
||||
memory->~U();
|
||||
template<class U>
|
||||
void destroy(U* ptr) {
|
||||
ptr->~U();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class type {
|
||||
friend class creator<type>;
|
||||
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static const type object;
|
||||
static unsigned instances;
|
||||
|
||||
protected:
|
||||
explicit type() {
|
||||
instances++;
|
||||
}
|
||||
|
||||
type(const type&) {
|
||||
instances++;
|
||||
explicit type(allow) {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances;
|
||||
const type type::object;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST(type::instances == 1);
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(creator<void>(), 3);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::allocate_shared<type[]>(creator<type>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<type[3]> result =
|
||||
boost::allocate_shared<type[3]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<type[][2]> result =
|
||||
boost::allocate_shared<type[][2]>(creator<type>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 1);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(creator<void>());
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
boost::shared_ptr<type[2][2]> result =
|
||||
boost::allocate_shared<type[2][2]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 1);
|
||||
{
|
||||
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(creator<void>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 5);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
boost::shared_ptr<const type[]> result =
|
||||
boost::allocate_shared<const type[]>(creator<type>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 1);
|
||||
{
|
||||
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(creator<void>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 5);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
boost::shared_ptr<const type[3]> result =
|
||||
boost::allocate_shared<const type[3]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 1);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(creator<void>(), 3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[][2]> result =
|
||||
boost::allocate_shared<const type[][2]>(creator<type>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 1);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(creator<void>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[2][2]> result =
|
||||
boost::allocate_shared<const type[2][2]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 1);
|
||||
{
|
||||
boost::shared_ptr<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(creator<void>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 5);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 1);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2]> a1 = boost::allocate_shared<const type[2][2]>(creator<void>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(type::instances == 5);
|
||||
a1.reset();
|
||||
BOOST_TEST(type::instances == 1);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,26 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
class type
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
template<class T>
|
||||
struct creator {
|
||||
typedef T value_type;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef creator<U> other;
|
||||
};
|
||||
|
||||
creator() { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>&) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||
}
|
||||
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class type
|
||||
: public boost::enable_shared_from_this<type> {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type() {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -28,30 +64,31 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::allocate_shared<type[]>(creator<type>(), 3);
|
||||
try {
|
||||
a1[0].shared_from_this();
|
||||
result[0].shared_from_this();
|
||||
BOOST_ERROR("shared_from_this did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 3);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::allocate_shared_noinit<type[]>(creator<type>(), 3);
|
||||
try {
|
||||
a1[0].shared_from_this();
|
||||
result[0].shared_from_this();
|
||||
BOOST_ERROR("shared_from_this did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 3);
|
||||
}
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,181 +1,251 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/align/is_aligned.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
template<class T>
|
||||
struct creator {
|
||||
typedef T value_type;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef creator<U> other;
|
||||
};
|
||||
|
||||
creator() { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>&) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||
}
|
||||
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type()
|
||||
: value_(0.0) {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
void set(long double value) {
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
long double get() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
|
||||
long double value_;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared_noinit<int[]>(std::allocator<int>(), 3);
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<int[]> result =
|
||||
boost::allocate_shared_noinit<int[]>(creator<int>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[3]> a1 = boost::allocate_shared_noinit<int[3]>(std::allocator<int>());
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<int[3]> result =
|
||||
boost::allocate_shared_noinit<int[3]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared_noinit<int[][2]>(std::allocator<int>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<int[][2]> result =
|
||||
boost::allocate_shared_noinit<int[][2]>(creator<int>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared_noinit<int[2][2]>(std::allocator<int>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<int[2][2]> result =
|
||||
boost::allocate_shared_noinit<int[2][2]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared_noinit<const int[]>(std::allocator<int>(), 3);
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<const int[]> result =
|
||||
boost::allocate_shared_noinit<const
|
||||
int[]>(creator<int>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared_noinit<const int[3]>(std::allocator<int>());
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<const int[3]> result =
|
||||
boost::allocate_shared_noinit<const int[3]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared_noinit<const int[][2]>(std::allocator<int>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const int[][2]> result =
|
||||
boost::allocate_shared_noinit<const
|
||||
int[][2]>(creator<int>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared_noinit<const int[2][2]>(std::allocator<int>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const int[2][2]> result =
|
||||
boost::allocate_shared_noinit<const
|
||||
int[2][2]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::allocate_shared_noinit<type[]>(creator<type>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::allocate_shared_noinit<type[3]>(std::allocator<type>());
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[3]> result =
|
||||
boost::allocate_shared_noinit<type[3]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[3]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[3]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[][2]> result =
|
||||
boost::allocate_shared_noinit<type[][2]>(creator<type>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared_noinit<type[2][2]>(std::allocator<type>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[2][2]> result =
|
||||
boost::allocate_shared_noinit<type[2][2]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[2][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::allocate_shared_noinit<const type[]>(std::allocator<type>(), 3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[]> result =
|
||||
boost::allocate_shared_noinit<const
|
||||
type[]>(creator<type>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared_noinit<const type[3]>(std::allocator<type>());
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[3]> result =
|
||||
boost::allocate_shared_noinit<const
|
||||
type[3]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[3]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2]> a1 = boost::allocate_shared_noinit<const type[][2]>(std::allocator<type>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[][2]> result =
|
||||
boost::allocate_shared_noinit<const
|
||||
type[][2]>(creator<type>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2]> a1 = boost::allocate_shared_noinit<const type[2][2]>(std::allocator<type>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[2][2]> result =
|
||||
boost::allocate_shared_noinit<const
|
||||
type[2][2]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[2][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,209 +1,266 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/align/is_aligned.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
template<class T>
|
||||
struct creator {
|
||||
typedef T value_type;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef creator<U> other;
|
||||
};
|
||||
|
||||
creator() { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>&) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||
}
|
||||
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type()
|
||||
: value_(0.0) {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
void set(long double value) {
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
long double get() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
|
||||
long double value_;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 3);
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<int[]> result =
|
||||
boost::allocate_shared<int[]>(creator<int>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[3]> a1 = boost::allocate_shared<int[3]>(std::allocator<int>());
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<int[3]> result =
|
||||
boost::allocate_shared<int[3]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<int[][2]> result =
|
||||
boost::allocate_shared<int[][2]>(creator<int>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<int[2][2]> result =
|
||||
boost::allocate_shared<int[2][2]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 3);
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<const int[]> result =
|
||||
boost::allocate_shared<const int[]>(creator<int>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared<const int[3]>(std::allocator<int>());
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<const int[3]> result =
|
||||
boost::allocate_shared<const int[3]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<const int[][2]> result =
|
||||
boost::allocate_shared<const int[][2]>(creator<int>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<const int[2][2]> result =
|
||||
boost::allocate_shared<const int[2][2]>(creator<int>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::allocate_shared<type[]>(creator<type>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[]> w1 = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>());
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[3]> result =
|
||||
boost::allocate_shared<type[3]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[3]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[3]> w1 = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[][2]> result =
|
||||
boost::allocate_shared<type[][2]>(creator<type>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(std::allocator<type>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[2][2]> result =
|
||||
boost::allocate_shared<type[2][2]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[]> result =
|
||||
boost::allocate_shared<const type[]>(creator<type>(), 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(std::allocator<type>());
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[3]> result =
|
||||
boost::allocate_shared<const type[3]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(std::allocator<type>(), 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[][2]> result =
|
||||
boost::allocate_shared<const type[][2]>(creator<type>(), 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2]> a1 = boost::allocate_shared<const type[2][2]>(std::allocator<type>());
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[2][2]> result =
|
||||
boost::allocate_shared<const type[2][2]>(creator<type>());
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,27 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
template<class T>
|
||||
struct creator {
|
||||
typedef T value_type;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef creator<U> other;
|
||||
};
|
||||
|
||||
creator() { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>&) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||
}
|
||||
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
type() {
|
||||
if (instances == 5) {
|
||||
throw true;
|
||||
}
|
||||
instances++;
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -29,72 +65,57 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
boost::allocate_shared<type[]>(std::allocator<type>(), 6);
|
||||
boost::allocate_shared<type[]>(creator<type>(), 6);
|
||||
BOOST_ERROR("allocate_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared<type[][2]>(std::allocator<type>(), 3);
|
||||
boost::allocate_shared<type[][2]>(creator<type>(), 3);
|
||||
BOOST_ERROR("allocate_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared<type[6]>(std::allocator<type>());
|
||||
boost::allocate_shared<type[6]>(creator<type>());
|
||||
BOOST_ERROR("allocate_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared<type[3][2]>(std::allocator<type>());
|
||||
boost::allocate_shared<type[3][2]>(creator<type>());
|
||||
BOOST_ERROR("allocate_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 6);
|
||||
boost::allocate_shared_noinit<type[]>(creator<type>(), 6);
|
||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 3);
|
||||
boost::allocate_shared_noinit<type[][2]>(creator<type>(), 3);
|
||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared_noinit<type[6]>(std::allocator<type>());
|
||||
boost::allocate_shared_noinit<type[6]>(creator<type>());
|
||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::allocate_shared_noinit<type[3][2]>(std::allocator<type>());
|
||||
boost::allocate_shared_noinit<type[3][2]>(creator<type>());
|
||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,46 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
int main() {
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 4, 1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
template<class T>
|
||||
struct creator {
|
||||
typedef T value_type;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef creator<U> other;
|
||||
};
|
||||
|
||||
creator() { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>&) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), 1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 4, 1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
boost::shared_ptr<int[]> result =
|
||||
boost::allocate_shared<int[]>(creator<int>(), 4, 1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[4]> a1 = boost::allocate_shared<const int[4]>(std::allocator<int>(), 1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
boost::shared_ptr<int[4]> result =
|
||||
boost::allocate_shared<int[4]>(creator<int>(), 1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[]> result =
|
||||
boost::allocate_shared<const int[]>(creator<int>(), 4, 1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[4]> result =
|
||||
boost::allocate_shared<const int[4]>(creator<int>(), 1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,48 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2, {0, 1});
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
template<class T>
|
||||
struct creator {
|
||||
typedef T value_type;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef creator<U> other;
|
||||
};
|
||||
|
||||
creator() { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>&) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), { 0, 1 });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>&, const creator<U>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 2, { 0, 1 });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
boost::shared_ptr<int[][2]> result =
|
||||
boost::allocate_shared<int[][2]>(creator<int>(), 2, {0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>(), { 0, 1 });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
boost::shared_ptr<int[2][2]> result =
|
||||
boost::allocate_shared<int[2][2]>(creator<int>(), {0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[][2]> result =
|
||||
boost::allocate_shared<const
|
||||
int[][2]>(creator<int>(), 2, {0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
{
|
||||
boost::shared_ptr<const int[2][2]> result =
|
||||
boost::allocate_shared<const
|
||||
int[2][2]>(creator<int>(), {0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
//
|
||||
// auto_ptr_rv_test.cpp
|
||||
//
|
||||
@@ -8,6 +10,14 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#if defined( BOOST_NO_AUTO_PTR )
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <memory>
|
||||
@@ -109,3 +119,5 @@ int main()
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined( BOOST_NO_AUTO_PTR )
|
||||
|
224
test/cpp11_pointer_cast_test.cpp
Normal file
224
test/cpp11_pointer_cast_test.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
//
|
||||
// cpp11_pointer_cast_test.cpp - a test for boost/pointer_cast.hpp with std::shared_ptr and std::unique_ptr
|
||||
//
|
||||
// Copyright (c) 2016 Karolin Varner
|
||||
//
|
||||
// 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/pointer_cast.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/get_pointer.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
||||
#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) \
|
||||
|| defined( BOOST_NO_CXX11_HDR_FUNCTIONAL ) \
|
||||
|| defined( BOOST_NO_CXX11_HDR_UTILITY ) \
|
||||
|| defined( BOOST_NO_CXX11_LAMBDAS ) \
|
||||
|| defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
// We expect all the features or none of the features to be
|
||||
// available, since we should be on C++11
|
||||
int main() { return 0; }
|
||||
|
||||
#else
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Let's create these inheritance relationship:
|
||||
//
|
||||
// base base2
|
||||
// | |
|
||||
// derived
|
||||
// |
|
||||
// derived_derived
|
||||
//
|
||||
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual ~base(){}
|
||||
int filler [5];
|
||||
};
|
||||
|
||||
class base2
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~base2(){}
|
||||
int filler [5];
|
||||
};
|
||||
|
||||
class derived
|
||||
: public base, public base2
|
||||
{
|
||||
int filler [5];
|
||||
};
|
||||
|
||||
class derived_derived
|
||||
: public derived
|
||||
{
|
||||
int filler [5];
|
||||
};
|
||||
|
||||
// And now some simple check functions
|
||||
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
|
||||
template <class BasePtr>
|
||||
bool check_dynamic_pointer_cast(const BasePtr &ptr)
|
||||
{
|
||||
//Check that dynamic_pointer_cast versus dynamic_cast
|
||||
return
|
||||
//Correct cast with dynamic_pointer_cast
|
||||
boost::get_pointer(boost::dynamic_pointer_cast<derived>(ptr)) ==
|
||||
//Correct cast with dynamic_cast
|
||||
dynamic_cast<derived*>(boost::get_pointer(ptr))
|
||||
&&
|
||||
//Incorrect cast with dynamic_pointer_cast
|
||||
boost::get_pointer(boost::dynamic_pointer_cast<derived_derived>(ptr)) ==
|
||||
//Incorrect cast with dynamic_cast
|
||||
dynamic_cast<derived_derived*>(boost::get_pointer(ptr));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <class BasePtr>
|
||||
bool check_static_pointer_cast(const BasePtr &ptr)
|
||||
{
|
||||
return
|
||||
//Cast base -> derived -> base2 using static_pointer_cast
|
||||
boost::get_pointer(
|
||||
boost::static_pointer_cast<base2>(
|
||||
boost::static_pointer_cast<derived>(ptr))) ==
|
||||
//Now the same with static_cast
|
||||
static_cast<base2*>(static_cast<derived*>(boost::get_pointer(ptr)));
|
||||
}
|
||||
|
||||
template <class BasePtr>
|
||||
bool check_const_pointer_cast(const BasePtr &ptr)
|
||||
{
|
||||
return
|
||||
//Unconst and const again using const_pointer_cast
|
||||
boost::get_pointer(
|
||||
boost::const_pointer_cast<const base>
|
||||
(boost::const_pointer_cast<base>(ptr))) ==
|
||||
//Now the same with const_cast
|
||||
const_cast<const base*>(const_cast<base*>(boost::get_pointer(ptr)));
|
||||
}
|
||||
|
||||
template <class BasePtr>
|
||||
void check_all_copy_casts(const BasePtr &ptr)
|
||||
{
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
BOOST_TEST( check_dynamic_pointer_cast( ptr ) );
|
||||
#endif
|
||||
BOOST_TEST( check_static_pointer_cast( ptr ) );
|
||||
BOOST_TEST( check_const_pointer_cast( ptr ) );
|
||||
}
|
||||
|
||||
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
|
||||
template <class BasePtr>
|
||||
bool check_dynamic_moving_pointer_cast(std::function<BasePtr()> f)
|
||||
{
|
||||
BasePtr smart1 = f(), smart2 = f();
|
||||
derived* expect1 = dynamic_cast<derived*>(boost::get_pointer(smart1));
|
||||
derived_derived* expect2 = dynamic_cast<derived_derived*>(boost::get_pointer(smart2));
|
||||
//Check that dynamic_pointer_cast versus dynamic_cast
|
||||
return
|
||||
//Correct cast with dynamic_pointer_cast
|
||||
boost::get_pointer(boost::dynamic_pointer_cast<derived>( std::move(smart1) )) == expect1
|
||||
&&
|
||||
//Incorrect cast with dynamic_pointer_cast
|
||||
boost::get_pointer(boost::dynamic_pointer_cast<derived_derived>( std::move(smart2) )) == expect2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <class BasePtr>
|
||||
bool check_static_moving_pointer_cast(std::function<BasePtr()> f)
|
||||
{
|
||||
BasePtr smart = f();
|
||||
base2 *expect = static_cast<base2*>(static_cast<derived*>(boost::get_pointer(smart)));
|
||||
|
||||
return
|
||||
//Cast base -> derived -> base2 using static_pointer_cast
|
||||
boost::get_pointer(
|
||||
boost::static_pointer_cast<base2>(
|
||||
boost::static_pointer_cast<derived>( std::move(smart) ))) ==
|
||||
//Now the same with static_cast
|
||||
expect;
|
||||
}
|
||||
|
||||
template <class BasePtr>
|
||||
bool check_const_moving_pointer_cast(std::function<BasePtr()> f)
|
||||
{
|
||||
BasePtr smart = f();
|
||||
const base *expect = const_cast<const base*>(const_cast<base*>(boost::get_pointer(smart)));
|
||||
return
|
||||
//Unconst and const again using const_pointer_cast
|
||||
boost::get_pointer(
|
||||
boost::const_pointer_cast<const base>
|
||||
(boost::const_pointer_cast<base>( std::move(smart) ))) ==
|
||||
//Now the same with const_cast
|
||||
expect;
|
||||
}
|
||||
|
||||
template <class BasePtr>
|
||||
void check_all_moving_casts(std::function<BasePtr()> f) {
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
BOOST_TEST( check_dynamic_moving_pointer_cast( f ) );
|
||||
#endif
|
||||
BOOST_TEST( check_static_moving_pointer_cast( f ) );
|
||||
BOOST_TEST( check_const_moving_pointer_cast( f ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::shared_ptr<base> std_shared(new derived);
|
||||
boost::shared_ptr<base> boost_shared(new derived);
|
||||
base *plain = boost_shared.get();
|
||||
|
||||
// plain & boost::shared_ptr moving pointer_cast checks; there
|
||||
// is no specific handleing for those types at the moment; this
|
||||
// test just makes sure they won't break when std::move() is used
|
||||
// in generic code
|
||||
|
||||
check_all_moving_casts<boost::shared_ptr<base>>([&boost_shared]() {
|
||||
return boost_shared;
|
||||
});
|
||||
|
||||
check_all_moving_casts<base*>([plain]() {
|
||||
return plain;
|
||||
});
|
||||
|
||||
// std::shared_ptr casts
|
||||
|
||||
check_all_copy_casts(std_shared);
|
||||
check_all_moving_casts<std::shared_ptr<base>>([&std_shared]() {
|
||||
return std_shared;
|
||||
});
|
||||
|
||||
// std::unique_ptr casts
|
||||
|
||||
check_all_moving_casts<std::unique_ptr<base>>([]() {
|
||||
return std::unique_ptr<base>(new derived);
|
||||
});
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#endif
|
@@ -15,6 +15,7 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -77,11 +78,15 @@ void test()
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
#if !defined( BOOST_NO_AUTO_PTR )
|
||||
|
||||
{
|
||||
std::auto_ptr<X> px( new X( 0 ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
|
@@ -143,6 +143,18 @@ int main()
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<Y> p( new Y );
|
||||
BOOST_TEST( N::base::instances == 1 );
|
||||
|
||||
boost::intrusive_ptr<X> p2( std::move( p ) );
|
||||
BOOST_TEST( N::base::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
|
||||
p2.reset();
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<X> p( new X );
|
||||
BOOST_TEST( N::base::instances == 1 );
|
||||
@@ -170,6 +182,33 @@ int main()
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<Y> p( new Y );
|
||||
BOOST_TEST( N::base::instances == 1 );
|
||||
|
||||
boost::intrusive_ptr<X> p2;
|
||||
p2 = std::move( p );
|
||||
BOOST_TEST( N::base::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
|
||||
p2.reset();
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::intrusive_ptr<Y> p( new Y );
|
||||
BOOST_TEST( N::base::instances == 1 );
|
||||
|
||||
boost::intrusive_ptr<X> p2( new X );
|
||||
BOOST_TEST( N::base::instances == 2 );
|
||||
p2 = std::move( p );
|
||||
BOOST_TEST( N::base::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
|
||||
p2.reset();
|
||||
BOOST_TEST( N::base::instances == 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
class type
|
||||
: public boost::enable_shared_from_this<type> {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type() {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -28,30 +27,31 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::make_shared<type[]>(3);
|
||||
try {
|
||||
a1[0].shared_from_this();
|
||||
result[0].shared_from_this();
|
||||
BOOST_ERROR("shared_from_this did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 3);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
||||
boost::shared_ptr<type[3]> result =
|
||||
boost::make_shared_noinit<type[3]>();
|
||||
try {
|
||||
a1[0].shared_from_this();
|
||||
result[0].shared_from_this();
|
||||
BOOST_ERROR("shared_from_this did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 3);
|
||||
}
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,181 +1,207 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/align/is_aligned.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type()
|
||||
: value_(0.0) {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
void set(long double value) {
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
long double get() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
|
||||
long double value_;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(3);
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<int[]> result =
|
||||
boost::make_shared_noinit<int[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[3]> a1 = boost::make_shared_noinit<int[3]>();
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<int[3]> result =
|
||||
boost::make_shared_noinit<int[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared_noinit<int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<int[][2]> result =
|
||||
boost::make_shared_noinit<int[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::make_shared_noinit<int[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<int[2][2]> result =
|
||||
boost::make_shared_noinit<int[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::make_shared_noinit<const int[]>(3);
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<const int[]> result =
|
||||
boost::make_shared_noinit<const int[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[3]> a1 = boost::make_shared_noinit<const int[3]>();
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
boost::shared_ptr<const int[3]> result =
|
||||
boost::make_shared_noinit<const int[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[][2]> a1 = boost::make_shared_noinit<const int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const int[][2]> result =
|
||||
boost::make_shared_noinit<const int[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared_noinit<const int[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const int[2][2]> result =
|
||||
boost::make_shared_noinit<const int[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::make_shared_noinit<type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::make_shared_noinit<type[3]>();
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[3]> result =
|
||||
boost::make_shared_noinit<type[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[3]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[3]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2]> a1 = boost::make_shared_noinit<type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[][2]> result =
|
||||
boost::make_shared_noinit<type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2]> a1 = boost::make_shared_noinit<type[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[2][2]> result =
|
||||
boost::make_shared_noinit<type[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[2][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::make_shared_noinit<const type[]>(3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[]> result =
|
||||
boost::make_shared_noinit<const type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::make_shared_noinit<const type[3]>();
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[3]> result =
|
||||
boost::make_shared_noinit<const type[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[3]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2]> a1 = boost::make_shared_noinit<const type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[][2]> result =
|
||||
boost::make_shared_noinit<const type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2]> a1 = boost::make_shared_noinit<const type[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[2][2]> result =
|
||||
boost::make_shared_noinit<const type[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
boost::weak_ptr<const type[2][2]> other = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,209 +1,229 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/align/is_aligned.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type()
|
||||
: value_(0.0) {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
void set(long double value) {
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
long double get() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
|
||||
long double value_;
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(3);
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<int[]> result =
|
||||
boost::make_shared<int[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[3]> a1 = boost::make_shared<int[3]>();
|
||||
int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<int[3]> result =
|
||||
boost::make_shared<int[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<int[][2]> result =
|
||||
boost::make_shared<int[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<int[2][2]> result =
|
||||
boost::make_shared<int[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(3);
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<const int[]> result =
|
||||
boost::make_shared<const int[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[3]> a1 = boost::make_shared<const int[3]>();
|
||||
const int* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
boost::shared_ptr<const int[3]> result =
|
||||
boost::make_shared<const int[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<const int[][2]> result =
|
||||
boost::make_shared<const int[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared<const int[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
boost::shared_ptr<const int[2][2]> result =
|
||||
boost::make_shared<const int[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<int>::value));
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[]> result =
|
||||
boost::make_shared<type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[]> w1 = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[3]> a1 = boost::make_shared<type[3]>();
|
||||
type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<type[3]> result =
|
||||
boost::make_shared<type[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
boost::weak_ptr<type[3]> w1 = a1;
|
||||
a1.reset();
|
||||
boost::weak_ptr<type[3]> w1 = result;
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[][2]> a1 = boost::make_shared<type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[][2]> result =
|
||||
boost::make_shared<type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<type[2][2]> a1 = boost::make_shared<type[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<type[2][2]> result =
|
||||
boost::make_shared<type[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[]> result =
|
||||
boost::make_shared<const type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[3]> a1 = boost::make_shared<const type[3]>();
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
BOOST_TEST(a2 != 0);
|
||||
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
|
||||
boost::shared_ptr<const type[3]> result =
|
||||
boost::make_shared<const type[3]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[][2]> a1 = boost::make_shared<const type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[][2]> result =
|
||||
boost::make_shared<const type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
boost::shared_ptr<const type[2][2]> a1 = boost::make_shared<const type[2][2]>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1.use_count() == 1);
|
||||
boost::shared_ptr<const type[2][2]> result =
|
||||
boost::make_shared<const type[2][2]>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result.use_count() == 1);
|
||||
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||
boost::alignment_of<type>::value));
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,27 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
type() {
|
||||
if (instances == 5) {
|
||||
throw true;
|
||||
}
|
||||
instances++;
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -29,72 +28,57 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
boost::make_shared<type[]>(6);
|
||||
BOOST_ERROR("make_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared<type[][2]>(3);
|
||||
BOOST_ERROR("make_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared<type[6]>();
|
||||
BOOST_ERROR("make_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared<type[3][2]>();
|
||||
BOOST_ERROR("make_shared did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared_noinit<type[]>(6);
|
||||
BOOST_ERROR("make_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared_noinit<type[][2]>(3);
|
||||
BOOST_ERROR("make_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared_noinit<type[6]>();
|
||||
BOOST_ERROR("make_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_shared_noinit<type[3][2]>();
|
||||
BOOST_ERROR("make_shared_noinit did not throw");
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,46 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(4, 1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
boost::shared_ptr<int[]> result =
|
||||
boost::make_shared<int[]>(4, 1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>(1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
boost::shared_ptr<int[4]> result =
|
||||
boost::make_shared<int[4]>(1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(4, 1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
boost::shared_ptr<const int[]> result =
|
||||
boost::make_shared<const int[]>(4, 1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[4]> a1 = boost::make_shared<const int[4]>(1);
|
||||
BOOST_TEST(a1[0] == 1);
|
||||
BOOST_TEST(a1[1] == 1);
|
||||
BOOST_TEST(a1[2] == 1);
|
||||
BOOST_TEST(a1[3] == 1);
|
||||
boost::shared_ptr<const int[4]> result =
|
||||
boost::make_shared<const int[4]>(1);
|
||||
BOOST_TEST(result[0] == 1);
|
||||
BOOST_TEST(result[1] == 1);
|
||||
BOOST_TEST(result[2] == 1);
|
||||
BOOST_TEST(result[3] == 1);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -1,48 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||
Copyright 2012-2015 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
boost::shared_ptr<int[][2]> result =
|
||||
boost::make_shared<int[][2]>(2, {0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ 0, 1 });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
boost::shared_ptr<int[2][2]> result =
|
||||
boost::make_shared<int[2][2]>({0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(2, { 0, 1 });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
boost::shared_ptr<const int[][2]> result =
|
||||
boost::make_shared<const int[][2]>(2, {0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared<const int[2][2]>({ 0, 1 });
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 1);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 1);
|
||||
boost::shared_ptr<const int[2][2]> result =
|
||||
boost::make_shared<const int[2][2]>({0, 1});
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 1);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
81
test/make_shared_move_emulation_test.cpp
Normal file
81
test/make_shared_move_emulation_test.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
// make_shared_move_emulation_test.cpp - a test of make_shared
|
||||
// semi-perfect forwarding of constructor arguments when using a C++03
|
||||
// compiler with move emulation.
|
||||
// Note the "semi": it means moving temporaries (real r-values) doesn't work.
|
||||
//
|
||||
// Copyright 2016 Giel van Schijndel
|
||||
//
|
||||
// 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/detail/lightweight_test.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class movearg
|
||||
{
|
||||
private:
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(movearg)
|
||||
public:
|
||||
movearg()
|
||||
{}
|
||||
movearg(BOOST_RV_REF(movearg))
|
||||
{}
|
||||
movearg& operator=(BOOST_RV_REF(movearg))
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class ByVal
|
||||
{
|
||||
public:
|
||||
ByVal(movearg) {}
|
||||
};
|
||||
|
||||
class ByRef
|
||||
{
|
||||
public:
|
||||
enum constructor_id
|
||||
{
|
||||
move_constructor,
|
||||
const_ref_constructor
|
||||
};
|
||||
|
||||
ByRef(BOOST_RV_REF(movearg)): constructed_by_(move_constructor)
|
||||
{}
|
||||
ByRef(const movearg &arg): constructed_by_(const_ref_constructor)
|
||||
{}
|
||||
|
||||
constructor_id constructed_by_;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
movearg a;
|
||||
boost::shared_ptr< ByVal > x = boost::make_shared< ByVal >(boost::move(a));
|
||||
}
|
||||
{
|
||||
movearg a;
|
||||
boost::shared_ptr< ByRef > x = boost::make_shared< ByRef >(boost::move(a));
|
||||
BOOST_TEST( x->constructed_by_ == ByRef::move_constructor);
|
||||
}
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
{
|
||||
boost::shared_ptr< ByVal > x = boost::make_shared< ByVal >(movearg());
|
||||
boost::shared_ptr< ByRef > y = boost::make_shared< ByRef >(movearg());
|
||||
BOOST_TEST( y->constructed_by_ == ByRef::move_constructor);
|
||||
}
|
||||
#endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
{
|
||||
const movearg ca;
|
||||
boost::shared_ptr< ByRef > x = boost::make_shared< ByRef >(ca);
|
||||
BOOST_TEST( x->constructed_by_ == ByRef::const_ref_constructor);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
19
test/make_shared_msvc_test.cpp
Normal file
19
test/make_shared_msvc_test.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// make_shared_msvc_test.cpp
|
||||
//
|
||||
// Copyright 2017 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
|
||||
//
|
||||
|
||||
template<class T> struct value
|
||||
{
|
||||
};
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -1,146 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type(int v1 = 0,
|
||||
int v2 = 0,
|
||||
int v3 = 0,
|
||||
int v4 = 0,
|
||||
int v5 = 0,
|
||||
int v6 = 0,
|
||||
int v7 = 0,
|
||||
int v8 = 0,
|
||||
int v9 = 0)
|
||||
: sum(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) {
|
||||
instances++;
|
||||
type(int v1 = 0,
|
||||
int v2 = 0,
|
||||
int v3 = 0,
|
||||
int v4 = 0,
|
||||
int v5 = 0,
|
||||
int v6 = 0,
|
||||
int v7 = 0,
|
||||
int v8 = 0,
|
||||
int v9 = 0)
|
||||
: sum_(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
const int sum;
|
||||
int sum() const {
|
||||
return sum_;
|
||||
}
|
||||
|
||||
private:
|
||||
int sum_;
|
||||
|
||||
type(const type&);
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result = boost::make_unique<type>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 0);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 0);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES )
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result = boost::make_unique<type>(1);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result = boost::make_unique<type>(1, 2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>(1, 2, 3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2 + 3);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>(1, 2, 3, 4);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>(1, 2, 3, 4, 5);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>(1, 2, 3, 4, 5, 6);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
|
||||
a1.reset();
|
||||
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type() {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -28,61 +27,61 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int[]> a1 = boost::make_unique_noinit<int[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<int[]> result =
|
||||
boost::make_unique_noinit<int[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int[][2]> a1 = boost::make_unique_noinit<int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<int[][2]> result =
|
||||
boost::make_unique_noinit<int[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type[]> a1 = boost::make_unique_noinit<type[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type[]> result =
|
||||
boost::make_unique_noinit<type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type[][2]> a1 = boost::make_unique_noinit<type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type[][2]> result =
|
||||
boost::make_unique_noinit<type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type[]> a1 = boost::make_unique_noinit<const type[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<const type[]> result =
|
||||
boost::make_unique_noinit<const type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type[][2]> a1 = boost::make_unique_noinit<const type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<const type[][2]> result =
|
||||
boost::make_unique_noinit<const type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type() {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -28,85 +27,84 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int[]> a1 = boost::make_unique<int[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
std::unique_ptr<int[]> result = boost::make_unique<int[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int[][2]> a1 = boost::make_unique<int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
std::unique_ptr<int[][2]> result =
|
||||
boost::make_unique<int[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const int[]> a1 = boost::make_unique<const int[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1[0] == 0);
|
||||
BOOST_TEST(a1[1] == 0);
|
||||
BOOST_TEST(a1[2] == 0);
|
||||
std::unique_ptr<const int[]> result =
|
||||
boost::make_unique<const int[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result[0] == 0);
|
||||
BOOST_TEST(result[1] == 0);
|
||||
BOOST_TEST(result[2] == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const int[][2]> a1 = boost::make_unique<const int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1[0][0] == 0);
|
||||
BOOST_TEST(a1[0][1] == 0);
|
||||
BOOST_TEST(a1[1][0] == 0);
|
||||
BOOST_TEST(a1[1][1] == 0);
|
||||
std::unique_ptr<const int[][2]> result =
|
||||
boost::make_unique<const int[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result[0][0] == 0);
|
||||
BOOST_TEST(result[0][1] == 0);
|
||||
BOOST_TEST(result[1][0] == 0);
|
||||
BOOST_TEST(result[1][1] == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type[]> a1 = boost::make_unique<type[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type[]> result =
|
||||
boost::make_unique<type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type[][2]> a1 = boost::make_unique<type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type[][2]> result =
|
||||
boost::make_unique<type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type[]> a1 = boost::make_unique<const type[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<const type[]> result =
|
||||
boost::make_unique<const type[]>(3);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type[][2]> a1 = boost::make_unique<const type[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<const type[][2]> result =
|
||||
boost::make_unique<const type[][2]>(2);
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 4);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,29 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
type() {
|
||||
if (instances == 5) {
|
||||
throw true;
|
||||
}
|
||||
instances++;
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -31,9 +30,10 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_unique<type[]>(6);
|
||||
@@ -41,7 +41,6 @@ int main() {
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_unique<type[][2]>(3);
|
||||
@@ -49,7 +48,6 @@ int main() {
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_unique_noinit<type[]>(6);
|
||||
@@ -57,7 +55,6 @@ int main() {
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_unique_noinit<type[][2]>(3);
|
||||
@@ -65,13 +62,11 @@ int main() {
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type() {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -28,38 +27,37 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int> a1 = boost::make_unique_noinit<int>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<int> result = boost::make_unique_noinit<int>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique_noinit<type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique_noinit<type>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique_noinit<const type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<const type> result =
|
||||
boost::make_unique_noinit<const type>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
instances++;
|
||||
type() {
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -28,45 +27,44 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int> a1 = boost::make_unique<int>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(*a1 == 0);
|
||||
std::unique_ptr<int> result = boost::make_unique<int>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(*result == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const int> a1 = boost::make_unique<const int>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(*a1 == 0);
|
||||
std::unique_ptr<const int> result =
|
||||
boost::make_unique<const int>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(*result == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<const type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
std::unique_ptr<const type> result =
|
||||
boost::make_unique<const type>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
a1.reset();
|
||||
result.reset();
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,29 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
class type {
|
||||
public:
|
||||
static unsigned int instances;
|
||||
static unsigned instances;
|
||||
|
||||
explicit type() {
|
||||
type() {
|
||||
if (instances == 0) {
|
||||
throw true;
|
||||
}
|
||||
instances++;
|
||||
++instances;
|
||||
}
|
||||
|
||||
~type() {
|
||||
instances--;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -31,9 +30,10 @@ private:
|
||||
type& operator=(const type&);
|
||||
};
|
||||
|
||||
unsigned int type::instances = 0;
|
||||
unsigned type::instances = 0;
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST(type::instances == 0);
|
||||
try {
|
||||
boost::make_unique<type>();
|
||||
@@ -41,13 +41,11 @@ int main() {
|
||||
} catch (...) {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,58 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
Copyright 2014 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
||||
#include <boost/smart_ptr/make_unique.hpp>
|
||||
|
||||
struct type {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1->x == 0);
|
||||
BOOST_TEST(a1->y == 0);
|
||||
std::unique_ptr<type> result = boost::make_unique<type>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result->x == 0);
|
||||
BOOST_TEST(result->y == 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<const type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1->x == 0);
|
||||
BOOST_TEST(a1->y == 0);
|
||||
std::unique_ptr<const type> result =
|
||||
boost::make_unique<const type>();
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result->x == 0);
|
||||
BOOST_TEST(result->y == 0);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>({ 1, 2 });
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1->x == 1);
|
||||
BOOST_TEST(a1->y == 2);
|
||||
std::unique_ptr<type> result =
|
||||
boost::make_unique<type>({ 1, 2 });
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result->x == 1);
|
||||
BOOST_TEST(result->y == 2);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<const type>({ 1, 2 });
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1->x == 1);
|
||||
BOOST_TEST(a1->y == 2);
|
||||
std::unique_ptr<const type> result =
|
||||
boost::make_unique<const type>({ 1, 2 });
|
||||
BOOST_TEST(result.get() != 0);
|
||||
BOOST_TEST(result->x == 1);
|
||||
BOOST_TEST(result->y == 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
18
test/pointer_cast_co_fail.cpp
Normal file
18
test/pointer_cast_co_fail.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// A negative test for unique_ptr const_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int> p1( new int );
|
||||
std::unique_ptr<int[]> p2 = boost::const_pointer_cast<int[]>( std::move( p1 ) );
|
||||
}
|
18
test/pointer_cast_co_fail2.cpp
Normal file
18
test/pointer_cast_co_fail2.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// A negative test for unique_ptr const_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
||||
std::unique_ptr<int> p2 = boost::const_pointer_cast<int>( std::move( p1 ) );
|
||||
}
|
29
test/pointer_cast_co_fail3.cpp
Normal file
29
test/pointer_cast_co_fail3.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// A negative test for unique_ptr const_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct B
|
||||
{
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct D: B
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<D[]> p1( new D[ 1 ] );
|
||||
std::unique_ptr<B[]> p2 = boost::const_pointer_cast<B[]>( std::move( p1 ) );
|
||||
}
|
25
test/pointer_cast_dy_fail.cpp
Normal file
25
test/pointer_cast_dy_fail.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// A negative test for unique_ptr dynamic_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct B
|
||||
{
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<B> p1( new B );
|
||||
std::unique_ptr<B[]> p2 = boost::dynamic_pointer_cast<B[]>( std::move( p1 ) );
|
||||
}
|
25
test/pointer_cast_dy_fail2.cpp
Normal file
25
test/pointer_cast_dy_fail2.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// A negative test for unique_ptr dynamic_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct B
|
||||
{
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<B[]> p1( new B[ 1 ] );
|
||||
std::unique_ptr<B> p2 = boost::dynamic_pointer_cast<B>( std::move( p1 ) );
|
||||
}
|
29
test/pointer_cast_dy_fail3.cpp
Normal file
29
test/pointer_cast_dy_fail3.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// A negative test for unique_ptr dynamic_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct B
|
||||
{
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct D: B
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<D[]> p1( new D[ 1 ] );
|
||||
std::unique_ptr<B[]> p2 = boost::dynamic_pointer_cast<B[]>( std::move( p1 ) );
|
||||
}
|
18
test/pointer_cast_st_fail.cpp
Normal file
18
test/pointer_cast_st_fail.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// A negative test for unique_ptr static_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int> p1( new int );
|
||||
std::unique_ptr<int[]> p2 = boost::static_pointer_cast<int[]>( std::move( p1 ) );
|
||||
}
|
18
test/pointer_cast_st_fail2.cpp
Normal file
18
test/pointer_cast_st_fail2.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// A negative test for unique_ptr static_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
||||
std::unique_ptr<int> p2 = boost::static_pointer_cast<int>( std::move( p1 ) );
|
||||
}
|
29
test/pointer_cast_st_fail3.cpp
Normal file
29
test/pointer_cast_st_fail3.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// A negative test for unique_ptr static_cast
|
||||
//
|
||||
// Copyright 2016 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/pointer_cast.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct B
|
||||
{
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct D: B
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<D[]> p1( new D[ 1 ] );
|
||||
std::unique_ptr<B[]> p2 = boost::static_pointer_cast<B[]>( std::move( p1 ) );
|
||||
}
|
@@ -104,33 +104,25 @@ bool check_const_pointer_cast(const BasePtr &ptr)
|
||||
const_cast<const base*>(const_cast<base*>(boost::get_pointer(ptr)));
|
||||
}
|
||||
|
||||
template <class BasePtr>
|
||||
void check_all_casts(const BasePtr &ptr)
|
||||
{
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
BOOST_TEST( check_dynamic_pointer_cast( ptr ) );
|
||||
#endif
|
||||
BOOST_TEST( check_static_pointer_cast( ptr ) );
|
||||
BOOST_TEST( check_const_pointer_cast( ptr ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
// Try casts with shared_ptr
|
||||
boost::shared_ptr<base> boost_shared(new derived);
|
||||
base *plain = boost_shared.get();
|
||||
|
||||
boost::shared_ptr<base> ptr(new derived);
|
||||
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
BOOST_TEST( check_dynamic_pointer_cast( ptr ) );
|
||||
#endif
|
||||
BOOST_TEST( check_static_pointer_cast( ptr ) );
|
||||
BOOST_TEST( check_const_pointer_cast( ptr ) );
|
||||
}
|
||||
|
||||
{
|
||||
// Try casts with raw pointer
|
||||
|
||||
boost::scoped_ptr<base> ptr(new derived);
|
||||
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
BOOST_TEST( check_dynamic_pointer_cast( ptr.get() ) );
|
||||
#endif
|
||||
BOOST_TEST( check_static_pointer_cast( ptr.get() ) );
|
||||
BOOST_TEST( check_const_pointer_cast( ptr.get() ) );
|
||||
}
|
||||
check_all_casts(boost_shared);
|
||||
check_all_casts(plain);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
247
test/pointer_cast_test2.cpp
Normal file
247
test/pointer_cast_test2.cpp
Normal file
@@ -0,0 +1,247 @@
|
||||
//
|
||||
// pointer_cast_test2.cpp - a test for unique_ptr casts
|
||||
//
|
||||
// Copyright 2016 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_CXX11_SMART_PTR )
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/pointer_cast.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <memory>
|
||||
|
||||
struct B1
|
||||
{
|
||||
};
|
||||
|
||||
struct D1: B1
|
||||
{
|
||||
~D1()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static void test_static_cast()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int> p1( new int );
|
||||
int * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<int> p2 = boost::static_pointer_cast<int>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int> p1( new int );
|
||||
int * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<int const> p2 = boost::static_pointer_cast<int const>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
||||
int * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<int[]> p2 = boost::static_pointer_cast<int[]>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
||||
int * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<int const[]> p2 = boost::static_pointer_cast<int const[]>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<D1> p1( new D1 );
|
||||
D1 * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<B1> p2 = boost::static_pointer_cast<B1>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
|
||||
std::unique_ptr<D1> p3 = boost::static_pointer_cast<D1>( std::move( p2 ) );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST_EQ( p3.get(), q1 );
|
||||
}
|
||||
}
|
||||
|
||||
static void test_const_cast()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int> p1( new int );
|
||||
int * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<int const> p2 = boost::const_pointer_cast<int const>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
|
||||
std::unique_ptr<int> p3 = boost::const_pointer_cast<int>( std::move( p2 ) );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST_EQ( p3.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
||||
int * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<int const[]> p2 = boost::const_pointer_cast<int const[]>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
|
||||
std::unique_ptr<int[]> p3 = boost::const_pointer_cast<int[]>( std::move( p2 ) );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST_EQ( p3.get(), q1 );
|
||||
}
|
||||
}
|
||||
|
||||
struct B2
|
||||
{
|
||||
virtual ~B2()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct C2
|
||||
{
|
||||
virtual ~C2()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct D2: B2, C2
|
||||
{
|
||||
};
|
||||
|
||||
static void test_dynamic_cast()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<D2> p1( new D2 );
|
||||
D2 * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<B2> p2 = boost::dynamic_pointer_cast<B2>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<B2> p1( new D2 );
|
||||
B2 * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<D2> p2 = boost::dynamic_pointer_cast<D2>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<B2> p1( new B2 );
|
||||
B2 * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<D2> p2 = boost::dynamic_pointer_cast<D2>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST_EQ( p1.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
D2 * q1 = new D2;
|
||||
std::unique_ptr<B2> p1( q1 );
|
||||
|
||||
std::unique_ptr<C2> p2 = boost::dynamic_pointer_cast<C2>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
}
|
||||
}
|
||||
|
||||
static void test_reinterpret_cast()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int> p1( new int );
|
||||
void * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<char> p2 = boost::reinterpret_pointer_cast<char>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
|
||||
p1 = boost::reinterpret_pointer_cast<int>( std::move( p2 ) );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST_EQ( p1.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int> p1( new int );
|
||||
void * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<char[]> p2 = boost::reinterpret_pointer_cast<char[]>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
|
||||
p1 = boost::reinterpret_pointer_cast<int>( std::move( p2 ) );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST_EQ( p1.get(), q1 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
||||
void * q1 = p1.get();
|
||||
|
||||
std::unique_ptr<char[]> p2 = boost::reinterpret_pointer_cast<char[]>( std::move( p1 ) );
|
||||
|
||||
BOOST_TEST( p1.get() == 0 );
|
||||
BOOST_TEST_EQ( p2.get(), q1 );
|
||||
|
||||
p1 = boost::reinterpret_pointer_cast<int[]>( std::move( p2 ) );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST_EQ( p1.get(), q1 );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_static_cast();
|
||||
test_const_cast();
|
||||
test_dynamic_cast();
|
||||
test_reinterpret_cast();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
@@ -16,8 +16,11 @@
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
template<class T, class U> void assert_same_type( T** pt = 0, U** pu = 0 )
|
||||
{
|
||||
pt = pu;
|
||||
@@ -58,12 +61,16 @@ int main()
|
||||
assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, void >::type, boost::intrusive_ptr<void> >();
|
||||
assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<void>, Y >::type, boost::intrusive_ptr<Y> >();
|
||||
|
||||
#if !defined( BOOST_NO_AUTO_PTR )
|
||||
|
||||
// auto_ptr
|
||||
|
||||
assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, Y >::type, std::auto_ptr<Y> >();
|
||||
assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, void >::type, std::auto_ptr<void> >();
|
||||
assert_same_type< boost::pointer_to_other< std::auto_ptr<void>, Y >::type, std::auto_ptr<Y> >();
|
||||
|
||||
#endif
|
||||
|
||||
// raw pointer
|
||||
|
||||
assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >();
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -75,11 +76,15 @@ void test()
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
#if !defined( BOOST_NO_AUTO_PTR )
|
||||
|
||||
{
|
||||
std::auto_ptr<X> px( new X( 0 ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
|
255
test/shared_ptr_alias_move_test.cpp
Normal file
255
test/shared_ptr_alias_move_test.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
// shared_ptr_alias_move_test.cpp
|
||||
//
|
||||
// Copyright (c) 2007 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/detail/lightweight_test.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <utility>
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
class incomplete;
|
||||
|
||||
struct X
|
||||
{
|
||||
static long instances;
|
||||
|
||||
int v_;
|
||||
|
||||
explicit X( int v ): v_( v )
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
v_ = 0;
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
X( X const & );
|
||||
X & operator=( X const & );
|
||||
};
|
||||
|
||||
long X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
int m = 0;
|
||||
boost::shared_ptr< int > p;
|
||||
boost::shared_ptr< int > p2( std::move( p ), &m );
|
||||
|
||||
BOOST_TEST( p2.get() == &m );
|
||||
BOOST_TEST( p2? true: false );
|
||||
BOOST_TEST( !!p2 );
|
||||
BOOST_TEST( p2.use_count() == 0 );
|
||||
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.use_count() == 0 );
|
||||
|
||||
p2.reset( std::move( p ), 0 );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p2? false: true );
|
||||
BOOST_TEST( !p2 );
|
||||
BOOST_TEST( p2.use_count() == 0 );
|
||||
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.use_count() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
int m = 0;
|
||||
boost::shared_ptr< int > p( new int );
|
||||
boost::shared_ptr< int const > p2( std::move( p ), &m );
|
||||
|
||||
BOOST_TEST( p2.get() == &m );
|
||||
BOOST_TEST( p2? true: false );
|
||||
BOOST_TEST( !!p2 );
|
||||
BOOST_TEST( p2.use_count() == 1 );
|
||||
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.use_count() == 0 );
|
||||
|
||||
boost::shared_ptr< int volatile > p3;
|
||||
p2.reset( std::move( p3 ), 0 );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p2? false: true );
|
||||
BOOST_TEST( !p2 );
|
||||
BOOST_TEST( p2.use_count() == 0 );
|
||||
|
||||
BOOST_TEST( p3.get() == 0 );
|
||||
BOOST_TEST( p3.use_count() == 0 );
|
||||
|
||||
boost::shared_ptr< int const volatile > p4( new int );
|
||||
p2.reset( std::move( p4 ), &m );
|
||||
|
||||
BOOST_TEST( p2.get() == &m );
|
||||
BOOST_TEST( p2.use_count() == 1 );
|
||||
|
||||
BOOST_TEST( p4.get() == 0 );
|
||||
BOOST_TEST( p4.use_count() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< int > p( new int );
|
||||
boost::shared_ptr< void const > p2( std::move( p ), 0 );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p2? false: true );
|
||||
BOOST_TEST( !p2 );
|
||||
BOOST_TEST( p2.use_count() == 1 );
|
||||
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.use_count() == 0 );
|
||||
|
||||
int m = 0;
|
||||
boost::shared_ptr< void volatile > p3;
|
||||
|
||||
p2.reset( std::move( p3 ), &m );
|
||||
|
||||
BOOST_TEST( p2.get() == &m );
|
||||
BOOST_TEST( p2? true: false );
|
||||
BOOST_TEST( !!p2 );
|
||||
BOOST_TEST( p2.use_count() == 0 );
|
||||
|
||||
BOOST_TEST( p3.get() == 0 );
|
||||
BOOST_TEST( p3.use_count() == 0 );
|
||||
|
||||
boost::shared_ptr< void const volatile > p4( new int );
|
||||
p2.reset( std::move( p4 ), 0 );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p2.use_count() == 1 );
|
||||
|
||||
BOOST_TEST( p4.get() == 0 );
|
||||
BOOST_TEST( p4.use_count() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< incomplete > p;
|
||||
boost::shared_ptr< incomplete > p2( std::move( p ), 0 );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p2? false: true );
|
||||
BOOST_TEST( !p2 );
|
||||
BOOST_TEST( p2.use_count() == 0 );
|
||||
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.use_count() == 0 );
|
||||
|
||||
p2.reset( std::move( p ), 0 );
|
||||
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p2? false: true );
|
||||
BOOST_TEST( !p2 );
|
||||
BOOST_TEST( p2.use_count() == 0 );
|
||||
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.use_count() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X > p( new X( 5 ) ), q( p );
|
||||
boost::shared_ptr< int const > p2( std::move( q ), &q->v_ );
|
||||
|
||||
BOOST_TEST( p2.get() == &p->v_ );
|
||||
BOOST_TEST( p2? true: false );
|
||||
BOOST_TEST( !!p2 );
|
||||
BOOST_TEST( p2.use_count() == p.use_count() );
|
||||
BOOST_TEST( !( p < p2 ) && !( p2 < p ) );
|
||||
|
||||
BOOST_TEST( q.get() == 0 );
|
||||
BOOST_TEST( q.use_count() == 0 );
|
||||
|
||||
p.reset();
|
||||
BOOST_TEST( *p2 == 5 );
|
||||
|
||||
boost::shared_ptr< X const > p3( new X( 8 ) ), q3( p3 );
|
||||
p2.reset( std::move( q3 ), &q3->v_ );
|
||||
|
||||
BOOST_TEST( p2.get() == &p3->v_ );
|
||||
BOOST_TEST( p2? true: false );
|
||||
BOOST_TEST( !!p2 );
|
||||
BOOST_TEST( p2.use_count() == p3.use_count() );
|
||||
BOOST_TEST( !( p3 < p2 ) && !( p2 < p3 ) );
|
||||
|
||||
BOOST_TEST( q3.get() == 0 );
|
||||
BOOST_TEST( q3.use_count() == 0 );
|
||||
|
||||
p3.reset();
|
||||
BOOST_TEST( *p2 == 8 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X > p( new X( 5 ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.unique() );
|
||||
BOOST_TEST( p->v_ == 5 );
|
||||
|
||||
boost::shared_ptr< X > p2( std::move( p ), p.get() );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p2.unique() );
|
||||
BOOST_TEST( p2->v_ == 5 );
|
||||
|
||||
boost::shared_ptr< int const > p3( std::move( p2 ), &p2->v_ );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p3.unique() );
|
||||
BOOST_TEST( *p3 == 5 );
|
||||
|
||||
p3.reset();
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr< X > p( new X( 5 ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.unique() );
|
||||
BOOST_TEST( p->v_ == 5 );
|
||||
|
||||
{
|
||||
boost::shared_ptr< X > p2(p);
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.get() == p2.get() );
|
||||
BOOST_TEST( p.use_count() == 2 );
|
||||
BOOST_TEST( p2.use_count() == 2 );
|
||||
|
||||
boost::shared_ptr< int const > p3( std::move( p2 ), &p2->v_ );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.use_count() == 2 );
|
||||
BOOST_TEST( p2.use_count() == 0 );
|
||||
BOOST_TEST( p2.get() == 0 );
|
||||
BOOST_TEST( p3.use_count() == 2 );
|
||||
BOOST_TEST( p3.get() == &p->v_ );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
BOOST_TEST( p.unique() );
|
||||
BOOST_TEST( p->v_ == 5 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
128
test/shared_ptr_alloc_construct11_test.cpp
Normal file
128
test/shared_ptr_alloc_construct11_test.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Copyright 2017 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
struct counters {
|
||||
unsigned allocate;
|
||||
unsigned construct;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class creator {
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
creator(counters* state)
|
||||
: state_(state) { }
|
||||
|
||||
template<class U>
|
||||
creator(const creator<U>& other)
|
||||
: state_(other.state()) { }
|
||||
|
||||
T* allocate(std::size_t size) {
|
||||
void* ptr = ::operator new(sizeof(T) * size);
|
||||
++state_->allocate;
|
||||
return static_cast<T*>(ptr);
|
||||
}
|
||||
|
||||
void deallocate(T* ptr, std::size_t) {
|
||||
::operator delete(ptr);
|
||||
--state_->allocate;
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
void construct(T* ptr, Args&&... args) {
|
||||
::new(static_cast<void*>(ptr)) T(std::forward<Args>(args)...);
|
||||
++state_->construct;
|
||||
}
|
||||
|
||||
void destroy(T* ptr) {
|
||||
ptr->~T();
|
||||
--state_->construct;
|
||||
}
|
||||
|
||||
counters* state() const {
|
||||
return state_;
|
||||
}
|
||||
|
||||
private:
|
||||
counters* state_;
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const creator<T>& lhs, const creator<U>& rhs)
|
||||
{
|
||||
return lhs.state() == rhs.state();
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const creator<T>& lhs, const creator<U>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
struct deleter {
|
||||
template<class U>
|
||||
void operator()(U ptr) const {
|
||||
delete ptr;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
counters state = { };
|
||||
boost::shared_ptr<int> pointer(new int(), deleter(),
|
||||
creator<int>(&state));
|
||||
BOOST_TEST(state.allocate == 1);
|
||||
BOOST_TEST(state.construct == 0);
|
||||
pointer.reset();
|
||||
BOOST_TEST(state.allocate == 0);
|
||||
}
|
||||
{
|
||||
counters state = { };
|
||||
boost::shared_ptr<int> pointer =
|
||||
boost::allocate_shared<int>(creator<int>(&state));
|
||||
BOOST_TEST(state.allocate == 1);
|
||||
BOOST_TEST(state.construct == 1);
|
||||
pointer.reset();
|
||||
BOOST_TEST(state.allocate == 0);
|
||||
BOOST_TEST(state.construct == 0);
|
||||
}
|
||||
{
|
||||
counters state = { };
|
||||
boost::shared_ptr<int[]> pointer =
|
||||
boost::allocate_shared<int[]>(creator<int>(&state), 5);
|
||||
BOOST_TEST(state.allocate == 1);
|
||||
BOOST_TEST(state.construct == 5);
|
||||
pointer.reset();
|
||||
BOOST_TEST(state.allocate == 0);
|
||||
BOOST_TEST(state.construct == 0);
|
||||
}
|
||||
{
|
||||
counters state = { };
|
||||
boost::shared_ptr<int[5]> pointer =
|
||||
boost::allocate_shared<int[5]>(creator<int>(&state));
|
||||
BOOST_TEST(state.allocate == 1);
|
||||
BOOST_TEST(state.construct == 5);
|
||||
pointer.reset();
|
||||
BOOST_TEST(state.allocate == 0);
|
||||
BOOST_TEST(state.construct == 0);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
55
test/shared_ptr_reinterpret_pointer_cast_test.cpp
Normal file
55
test/shared_ptr_reinterpret_pointer_cast_test.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// shared_pointer_reinterpret_pointer_cast_test.cpp
|
||||
//
|
||||
// Copyright (c) 2016 Chris Glover
|
||||
//
|
||||
// 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/shared_ptr.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
struct X
|
||||
{};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<char> pc;
|
||||
|
||||
boost::shared_ptr<int> pi = boost::reinterpret_pointer_cast<int>(pc);
|
||||
BOOST_TEST(pi.get() == 0);
|
||||
|
||||
boost::shared_ptr<X> px = boost::reinterpret_pointer_cast<X>(pc);
|
||||
BOOST_TEST(px.get() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int> pi(new int);
|
||||
boost::shared_ptr<char> pc = boost::reinterpret_pointer_cast<char>(pi);
|
||||
|
||||
boost::shared_ptr<int> pi2 = boost::reinterpret_pointer_cast<int>(pc);
|
||||
BOOST_TEST(pi.get() == pi2.get());
|
||||
BOOST_TEST(!(pi < pi2 || pi2 < pi));
|
||||
BOOST_TEST(pi.use_count() == 3);
|
||||
BOOST_TEST(pc.use_count() == 3);
|
||||
BOOST_TEST(pi2.use_count() == 3);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<X> px(new X);
|
||||
boost::shared_ptr<char> pc = boost::reinterpret_pointer_cast<char>(px);
|
||||
|
||||
boost::shared_ptr<X> px2 = boost::reinterpret_pointer_cast<X>(pc);
|
||||
BOOST_TEST(px.get() == px2.get());
|
||||
BOOST_TEST(!(px < px2 || px2 < px));
|
||||
BOOST_TEST(px.use_count() == 3);
|
||||
BOOST_TEST(pc.use_count() == 3);
|
||||
BOOST_TEST(px2.use_count() == 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
106
test/shared_ptr_rv_pointer_cast_test.cpp
Normal file
106
test/shared_ptr_rv_pointer_cast_test.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// shared_ptr_rv_pointer_cast_test.cpp
|
||||
//
|
||||
// Copyright (c) 2016 Chris Glover
|
||||
//
|
||||
// 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/shared_ptr.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
struct X
|
||||
{};
|
||||
|
||||
struct Y: public X
|
||||
{};
|
||||
|
||||
struct U
|
||||
{
|
||||
virtual ~U() {}
|
||||
};
|
||||
|
||||
struct V: public U
|
||||
{};
|
||||
|
||||
struct W : public U
|
||||
{};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<X> px(new Y);
|
||||
|
||||
boost::shared_ptr<Y> py1 = boost::static_pointer_cast<Y>(px);
|
||||
boost::shared_ptr<Y> py2 = boost::static_pointer_cast<Y>(std::move(px));
|
||||
BOOST_TEST(!px);
|
||||
BOOST_TEST(px.use_count() == 0);
|
||||
BOOST_TEST(py1.get() == py2.get());
|
||||
BOOST_TEST(!(py1 < py2 || py2 < py1));
|
||||
BOOST_TEST(py1.use_count() == 2);
|
||||
BOOST_TEST(py2.use_count() == 2);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int const volatile> px(new int);
|
||||
|
||||
boost::shared_ptr<int> px2 = boost::const_pointer_cast<int>(px);
|
||||
boost::shared_ptr<int> px3 = boost::const_pointer_cast<int>(std::move(px));
|
||||
BOOST_TEST(!px);
|
||||
BOOST_TEST(px.use_count() == 0);
|
||||
BOOST_TEST(px2.get() == px3.get());
|
||||
BOOST_TEST(!(px2 < px3 || px2 < px3));
|
||||
BOOST_TEST(px2.use_count() == 2);
|
||||
BOOST_TEST(px3.use_count() == 2);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<char> pv(reinterpret_cast<char*>(new Y));
|
||||
|
||||
boost::shared_ptr<Y> py1 = boost::reinterpret_pointer_cast<Y>(pv);
|
||||
boost::shared_ptr<Y> py2 = boost::reinterpret_pointer_cast<Y>(std::move(pv));
|
||||
BOOST_TEST(!pv);
|
||||
BOOST_TEST(pv.use_count() == 0);
|
||||
BOOST_TEST(py1.get() == py2.get());
|
||||
BOOST_TEST(!(py1 < py2 || py2 < py1));
|
||||
BOOST_TEST(py1.use_count() == 2);
|
||||
BOOST_TEST(py2.use_count() == 2);
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_RTTI )
|
||||
{
|
||||
boost::shared_ptr<U> pu(new V);
|
||||
|
||||
boost::shared_ptr<V> pv1 = boost::dynamic_pointer_cast<V>(pu);
|
||||
boost::shared_ptr<V> pv2 = boost::dynamic_pointer_cast<V>(std::move(pu));
|
||||
BOOST_TEST(!pu);
|
||||
BOOST_TEST(pu.use_count() == 0);
|
||||
BOOST_TEST(pv1.get() == pv2.get());
|
||||
BOOST_TEST(!(pv1 < pv2 || pv2 < pv1));
|
||||
BOOST_TEST(pv1.use_count() == 2);
|
||||
BOOST_TEST(pv2.use_count() == 2);
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<U> pu(new V);
|
||||
boost::shared_ptr<W> pw = boost::dynamic_pointer_cast<W>(std::move(pu));
|
||||
BOOST_TEST(!pw);
|
||||
BOOST_TEST(pu);
|
||||
}
|
||||
#endif // !defined( BOOST_NO_RTTI )
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
@@ -850,6 +850,8 @@ void weak_ptr_constructor()
|
||||
|
||||
void auto_ptr_constructor()
|
||||
{
|
||||
#if !defined( BOOST_NO_AUTO_PTR )
|
||||
|
||||
{
|
||||
std::auto_ptr<int> p;
|
||||
boost::shared_ptr<int> pi(p);
|
||||
@@ -1136,6 +1138,8 @@ void auto_ptr_constructor()
|
||||
|
||||
BOOST_TEST(X::instances == 0);
|
||||
BOOST_TEST(Y::instances == 0);
|
||||
|
||||
#endif // #if !defined( BOOST_NO_AUTO_PTR )
|
||||
}
|
||||
|
||||
void test()
|
||||
@@ -1420,6 +1424,8 @@ void conversion_assignment()
|
||||
|
||||
void auto_ptr_assignment()
|
||||
{
|
||||
#if !defined( BOOST_NO_AUTO_PTR )
|
||||
|
||||
{
|
||||
boost::shared_ptr<int> p1;
|
||||
|
||||
@@ -1516,6 +1522,8 @@ void auto_ptr_assignment()
|
||||
BOOST_TEST(X::instances == 0);
|
||||
BOOST_TEST(Y::instances == 0);
|
||||
}
|
||||
|
||||
#endif // #if !defined( BOOST_NO_AUTO_PTR )
|
||||
}
|
||||
|
||||
void test()
|
||||
|
34
test/sp_hash_test2.cpp
Normal file
34
test/sp_hash_test2.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// sp_hash_test2.cpp
|
||||
//
|
||||
// Copyright 2011, 2015 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/shared_ptr.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::hash< boost::shared_ptr<int[]> > hasher;
|
||||
|
||||
boost::shared_ptr< int[] > p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
34
test/sp_hash_test3.cpp
Normal file
34
test/sp_hash_test3.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// sp_hash_test3.cpp
|
||||
//
|
||||
// Copyright 2011, 2015 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/shared_ptr.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::hash< boost::shared_ptr<int[1]> > hasher;
|
||||
|
||||
boost::shared_ptr< int[1] > p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
96
test/sp_nothrow_test.cpp
Normal file
96
test/sp_nothrow_test.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// sp_nothrow_test.cpp
|
||||
//
|
||||
// Copyright 2016 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_CXX11_HDR_TYPE_TRAITS )
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
template<class T> void test_copy()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_constructible<T> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_assignable<T> ));
|
||||
}
|
||||
|
||||
template<class T> void test_move()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<T> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<T> ));
|
||||
}
|
||||
|
||||
template<class T> void test_default()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_default_constructible<T> ));
|
||||
}
|
||||
|
||||
template<class T> void test_destroy()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_destructible<T> ));
|
||||
}
|
||||
|
||||
template<class T> void test_cmd()
|
||||
{
|
||||
test_copy<T>();
|
||||
test_move<T>();
|
||||
test_default<T>();
|
||||
}
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y: public boost::enable_shared_from_this<Y>
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
test_cmd< boost::shared_ptr<X> >();
|
||||
test_cmd< boost::shared_array<X> >();
|
||||
test_cmd< boost::weak_ptr<X> >();
|
||||
|
||||
test_copy< Y >();
|
||||
test_default< Y >();
|
||||
test_destroy< Y >();
|
||||
|
||||
// test_move< Y >();
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<Y> ));
|
||||
|
||||
#if !( defined( BOOST_MSVC ) && BOOST_MSVC == 1700 )
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<Y> ));
|
||||
|
||||
#endif
|
||||
|
||||
test_default< boost::scoped_ptr<X> >();
|
||||
test_default< boost::scoped_array<X> >();
|
||||
|
||||
test_move< boost::intrusive_ptr<X> >();
|
||||
test_default< boost::intrusive_ptr<X> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS )
|
Reference in New Issue
Block a user