mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-05 12:11:07 +02:00
Compare commits
114 Commits
boost-1.56
...
boost-1.63
Author | SHA1 | Date | |
---|---|---|---|
|
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 | ||
|
4db7219c32 | ||
|
3f17244225 | ||
|
ca93749614 | ||
|
05d5a4e9a0 | ||
|
970a179ac2 | ||
|
a06123eb87 | ||
|
fd543d3292 | ||
|
df90496583 | ||
|
20ead68473 | ||
|
79cde147c9 | ||
|
abbe975e8f | ||
|
8ba0730686 | ||
|
686efe100b | ||
|
acb880d8c2 | ||
|
1712b87cb6 | ||
|
f8943703f8 | ||
|
a42dda0af4 | ||
|
9b9b6d3ca6 | ||
|
d875a68ceb | ||
|
8cb2c56556 | ||
|
290fe82a43 | ||
|
94824c807f | ||
|
334654de06 | ||
|
0ab0e6eecc | ||
|
effc9f73d6 | ||
|
99762e7dde | ||
|
add539142b | ||
|
e067fd2cfd | ||
|
212528860a | ||
|
711c36958a | ||
|
7104e7dc7e | ||
|
254bda34b7 | ||
|
3fd53ced83 | ||
|
75de3dbcf1 | ||
|
7faec4265b | ||
|
c81d0806e4 | ||
|
a74329794c | ||
|
71756350d9 | ||
|
f65c57d9d2 | ||
|
b1fc261fe6 | ||
|
aedcf3ccda | ||
|
a1a5999a38 | ||
|
8afd3bee69 | ||
|
2a56c73924 | ||
|
720ce12a25 | ||
|
2be09db523 | ||
|
de10be8560 | ||
|
7b71068b52 | ||
|
6b562cb5b1 | ||
|
3d2c230623 | ||
|
553c7994ba | ||
|
280aadfcdb | ||
|
59ac922a1c | ||
|
8de3e84021 | ||
|
bd4f9c239a | ||
|
528195233b | ||
|
8c49f5a637 | ||
|
88f0a98d71 | ||
|
96d82e0275 | ||
|
40387ef654 |
50
.travis.yml
Normal file
50
.travis.yml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
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 init tools/inspect
|
||||||
|
- git submodule update
|
||||||
|
- cp -r $TRAVIS_BUILD_DIR/* libs/smart_ptr
|
||||||
|
- ./bootstrap.sh
|
||||||
|
- ./b2 headers
|
||||||
|
|
||||||
|
script:
|
||||||
|
- TOOLSET=gcc,clang
|
||||||
|
- if [ $TRAVIS_OS_NAME == osx ]; then TOOLSET=clang; fi
|
||||||
|
- ./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)
|
42
appveyor.yml
Normal file
42
appveyor.yml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# 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 init tools/inspect
|
||||||
|
- 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
|
@@ -2,21 +2,25 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>enable_shared_from_this</title>
|
<title>enable_shared_from_this</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>
|
</head>
|
||||||
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
||||||
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
||||||
width="277" align="middle" border="0">enable_shared_from_this</h1>
|
width="277" align="middle" border="0" />enable_shared_from_this</h1>
|
||||||
<h2><a name="Purpose">Purpose</a></h2>
|
<h2><a name="Purpose">Purpose</a></h2>
|
||||||
<p>
|
<p>
|
||||||
The header <STRONG><boost/enable_shared_from_this.hpp></STRONG> defines
|
The header <code><boost/enable_shared_from_this.hpp></code> defines
|
||||||
the class template <STRONG>enable_shared_from_this</STRONG>. It is used as a
|
the class template <code>enable_shared_from_this</code>. It is used as a
|
||||||
base class that allows a <A href="shared_ptr.htm">shared_ptr</A> to the current
|
base class that allows a <a href="shared_ptr.htm">shared_ptr</a> or
|
||||||
object to be obtained from within a member function.
|
a <a href="weak_ptr.htm">weak_ptr</a> to the current object to be obtained
|
||||||
|
from within a member function.
|
||||||
|
</p>
|
||||||
|
<p><code>enable_shared_from_this<T></code> defines two member functions
|
||||||
|
called <code>shared_from_this</code> that return a <code>shared_ptr<T></code>
|
||||||
|
and <code>shared_ptr<T const></code>, depending on constness, to <code>this</code>.
|
||||||
|
It also defines two member functions called <code>weak_from_this</code> that return
|
||||||
|
a corresponding <code>weak_ptr</code>.
|
||||||
</p>
|
</p>
|
||||||
<P><STRONG>enable_shared_from_this<T></STRONG> defines two member functions
|
|
||||||
called <STRONG>shared_from_this</STRONG> that return a <STRONG>shared_ptr<T></STRONG>
|
|
||||||
and <STRONG>shared_ptr<T const></STRONG>, depending on constness, to <STRONG>this</STRONG>.</P>
|
|
||||||
<h2><a name="Example">Example</a></h2>
|
<h2><a name="Example">Example</a></h2>
|
||||||
<pre>
|
<pre>
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
@@ -41,7 +45,7 @@ int main()
|
|||||||
assert(!(p < q || q < p)); // p and q must share ownership
|
assert(!(p < q || q < p)); // p and q must share ownership
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
<h3><a name="Synopsis">Synopsis</a></h3>
|
<h2><a name="Synopsis">Synopsis</a></h2>
|
||||||
<pre>
|
<pre>
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@@ -52,34 +56,55 @@ public:
|
|||||||
|
|
||||||
shared_ptr<T> shared_from_this();
|
shared_ptr<T> shared_from_this();
|
||||||
shared_ptr<T const> shared_from_this() const;
|
shared_ptr<T const> shared_from_this() const;
|
||||||
|
|
||||||
|
weak_ptr<T> weak_from_this() noexcept;
|
||||||
|
weak_ptr<T const> weak_from_this() const noexcept;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
<h4>template<class T> shared_ptr<T>
|
<h4><code>template<class T> shared_ptr<T>
|
||||||
enable_shared_from_this<T>::shared_from_this();</h4>
|
enable_shared_from_this<T>::shared_from_this();</code></h4>
|
||||||
<h4>template<class T> shared_ptr<T const>
|
<h4><code>template<class T> shared_ptr<T const>
|
||||||
enable_shared_from_this<T>::shared_from_this() const;</h4>
|
enable_shared_from_this<T>::shared_from_this() const;</code></h4>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<b>Requires:</b> <STRONG>enable_shared_from_this<T></STRONG> must be an
|
<b>Requires:</b> <code>enable_shared_from_this<T></code> must be an
|
||||||
accessible base class of <b>T</b>. <STRONG>*this</STRONG> must be a subobject
|
accessible base class of <code>T</code>. <code>*this</code> must be a subobject
|
||||||
of an instance <STRONG>t</STRONG> of type <STRONG>T</STRONG> . There must exist
|
of an instance <code>t</code> of type <code>T</code>.
|
||||||
at least one <STRONG>shared_ptr</STRONG> instance <STRONG>p</STRONG> that <EM>owns</EM>
|
|
||||||
<STRONG>t</STRONG>.
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b>Returns:</b> A <b>shared_ptr<T></b> instance <b>r</b> that shares
|
<b>Returns:</b> If a <code>shared_ptr</code> instance <code>p</code> that <em>owns</em>
|
||||||
ownership with <b>p</b>.
|
<code>t</code> exists, a <code>shared_ptr<T></code> instance <code>r</code> that shares
|
||||||
|
ownership with <code>p</code>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b>Postconditions:</b> <tt>r.get() == this</tt>.
|
<b>Postconditions:</b> <code>r.get() == this</code>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Throws:</b> <code>bad_weak_ptr</code> when no <code>shared_ptr</code> <em>owns</em> <code>*this</code>.
|
||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<p>$Date$</p>
|
<h4><code>template<class T> weak_ptr<T>
|
||||||
|
enable_shared_from_this<T>::weak_from_this() noexcept;</code></h4>
|
||||||
|
<h4><code>template<class T> weak_ptr<T const>
|
||||||
|
enable_shared_from_this<T>::weak_from_this() const noexcept;</code></h4>
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<b>Requires:</b> <code>enable_shared_from_this<T></code> must be an
|
||||||
|
accessible base class of <code>T</code>. <code>*this</code> must be a subobject
|
||||||
|
of an instance <code>t</code> of type <code>T</code>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Returns:</b> If a <code>shared_ptr</code> instance <code>p</code> that <em>owns</em>
|
||||||
|
<code>t</code> exists or has existed in the past, a <code>weak_ptr<T></code> instance
|
||||||
|
<code>r</code> that shares ownership with <code>p</code>. Otherwise, an empty <code>weak_ptr</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
<hr />
|
||||||
<p>
|
<p>
|
||||||
<small>Copyright © 2002, 2003 by Peter Dimov. Distributed under the Boost Software License, Version
|
<small>Copyright © 2002, 2003, 2015 by Peter Dimov. Distributed under the Boost Software License, Version
|
||||||
1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or
|
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>
|
copy at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>.</small></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#ifndef BOOST_MAKE_UNIQUE_HPP_INCLUDED
|
#ifndef BOOST_MAKE_UNIQUE_HPP_INCLUDED
|
||||||
#define BOOST_MAKE_UNIQUE_HPP_INCLUDED
|
#define BOOST_MAKE_UNIQUE_HPP_INCLUDED
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
#ifndef BOOST_POINTER_CAST_HPP
|
#ifndef BOOST_POINTER_CAST_HPP
|
||||||
#define BOOST_POINTER_CAST_HPP
|
#define BOOST_POINTER_CAST_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
//static_pointer_cast overload for raw pointers
|
//static_pointer_cast overload for raw pointers
|
||||||
@@ -42,4 +44,78 @@ inline T* reinterpret_pointer_cast(U *ptr)
|
|||||||
|
|
||||||
} // namespace boost
|
} // 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
|
#endif //BOOST_POINTER_CAST_HPP
|
||||||
|
@@ -36,6 +36,11 @@ namespace boost
|
|||||||
# pragma option push -pc
|
# pragma option push -pc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic push
|
||||||
|
# pragma clang diagnostic ignored "-Wweak-vtables"
|
||||||
|
#endif
|
||||||
|
|
||||||
class bad_weak_ptr: public std::exception
|
class bad_weak_ptr: public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -46,6 +51,10 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__BORLANDC__) && __BORLANDC__ <= 0x564
|
#if defined(__BORLANDC__) && __BORLANDC__ <= 0x564
|
||||||
# pragma option pop
|
# pragma option pop
|
||||||
#endif
|
#endif
|
||||||
|
@@ -213,7 +213,7 @@ namespace boost {
|
|||||||
typedef Y* pointer;
|
typedef Y* pointer;
|
||||||
typedef const Y* const_pointer;
|
typedef const Y* const_pointer;
|
||||||
typedef std::size_t size_type;
|
typedef std::size_t size_type;
|
||||||
typedef ptrdiff_t difference_type;
|
typedef std::ptrdiff_t difference_type;
|
||||||
typedef Y& reference;
|
typedef Y& reference;
|
||||||
typedef const Y& const_reference;
|
typedef const Y& const_reference;
|
||||||
|
|
||||||
|
@@ -73,6 +73,9 @@
|
|||||||
#elif defined( BOOST_DISABLE_THREADS ) && !defined( BOOST_SP_ENABLE_THREADS ) && !defined( BOOST_DISABLE_WIN32 )
|
#elif defined( BOOST_DISABLE_THREADS ) && !defined( BOOST_SP_ENABLE_THREADS ) && !defined( BOOST_DISABLE_WIN32 )
|
||||||
# include <boost/smart_ptr/detail/atomic_count_nt.hpp>
|
# 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__ )
|
#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) && !defined( __PATHSCALE__ )
|
||||||
# include <boost/smart_ptr/detail/atomic_count_gcc_x86.hpp>
|
# include <boost/smart_ptr/detail/atomic_count_gcc_x86.hpp>
|
||||||
|
|
||||||
|
@@ -6,7 +6,8 @@
|
|||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) && !defined( BOOST_NO_CXX11_NULLPTR )
|
#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) && !defined( BOOST_NO_CXX11_NULLPTR )\
|
||||||
|
&& !(defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5130))
|
||||||
|
|
||||||
explicit operator bool () const BOOST_NOEXCEPT
|
explicit operator bool () const BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <boost/smart_ptr/bad_weak_ptr.hpp>
|
#include <boost/smart_ptr/bad_weak_ptr.hpp>
|
||||||
#include <boost/smart_ptr/detail/sp_counted_base.hpp>
|
#include <boost/smart_ptr/detail/sp_counted_base.hpp>
|
||||||
#include <boost/smart_ptr/detail/sp_counted_impl.hpp>
|
#include <boost/smart_ptr/detail/sp_counted_impl.hpp>
|
||||||
|
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
|
||||||
#include <boost/detail/workaround.hpp>
|
#include <boost/detail/workaround.hpp>
|
||||||
// In order to avoid circular dependencies with Boost.TR1
|
// In order to avoid circular dependencies with Boost.TR1
|
||||||
// we make sure that our include of <memory> doesn't try to
|
// we make sure that our include of <memory> doesn't try to
|
||||||
@@ -40,13 +41,23 @@
|
|||||||
# include <new> // std::bad_alloc
|
# include <new> // std::bad_alloc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined( BOOST_NO_CXX11_SMART_PTR )
|
#include <boost/core/addressof.hpp>
|
||||||
# include <boost/utility/addressof.hpp>
|
|
||||||
|
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
|
namespace movelib
|
||||||
|
{
|
||||||
|
|
||||||
|
template< class T, class D > class unique_ptr;
|
||||||
|
|
||||||
|
} // namespace movelib
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -63,8 +74,6 @@ template< class D > struct sp_inplace_tag
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined( BOOST_NO_CXX11_SMART_PTR )
|
|
||||||
|
|
||||||
template< class T > class sp_reference_wrapper
|
template< class T > class sp_reference_wrapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -93,8 +102,6 @@ template< class D > struct sp_convert_reference< D& >
|
|||||||
typedef sp_reference_wrapper< D > type;
|
typedef sp_reference_wrapper< D > type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class weak_count;
|
class weak_count;
|
||||||
|
|
||||||
class shared_count
|
class shared_count
|
||||||
@@ -438,6 +445,29 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<class Y, class D>
|
||||||
|
explicit shared_count( boost::movelib::unique_ptr<Y, D> & r ): pi_( 0 )
|
||||||
|
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||||
|
, id_(shared_count_id)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
typedef typename sp_convert_reference<D>::type D2;
|
||||||
|
|
||||||
|
D2 d2( r.get_deleter() );
|
||||||
|
pi_ = new sp_counted_impl_pd< typename boost::movelib::unique_ptr<Y, D>::pointer, D2 >( r.get(), d2 );
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_EXCEPTIONS
|
||||||
|
|
||||||
|
if( pi_ == 0 )
|
||||||
|
{
|
||||||
|
boost::throw_exception( std::bad_alloc() );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
r.release();
|
||||||
|
}
|
||||||
|
|
||||||
~shared_count() // nothrow
|
~shared_count() // nothrow
|
||||||
{
|
{
|
||||||
if( pi_ != 0 ) pi_->release();
|
if( pi_ != 0 ) pi_->release();
|
||||||
@@ -668,6 +698,10 @@ inline shared_count::shared_count( weak_count const & r, sp_nothrow_tag ): pi_(
|
|||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
# pragma warn .8027 // Functions containing try are not expanded inline
|
# pragma warn .8027 // Functions containing try are not expanded inline
|
||||||
#endif
|
#endif
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
// http://www.boost.org/LICENSE_1_0.txt
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( BOOST_NO_SFINAE )
|
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE ) && defined( BOOST_NO_SFINAE )
|
||||||
# define BOOST_SP_NO_SP_CONVERTIBLE
|
# define BOOST_SP_NO_SP_CONVERTIBLE
|
||||||
|
@@ -20,6 +20,12 @@
|
|||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/smart_ptr/detail/sp_has_sync.hpp>
|
#include <boost/smart_ptr/detail/sp_has_sync.hpp>
|
||||||
|
|
||||||
|
#if defined( __clang__ ) && defined( __has_extension )
|
||||||
|
# if __has_extension( __c_atomic__ )
|
||||||
|
# define BOOST_SP_HAS_CLANG_C11_ATOMICS
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined( BOOST_SP_DISABLE_THREADS )
|
#if defined( BOOST_SP_DISABLE_THREADS )
|
||||||
# include <boost/smart_ptr/detail/sp_counted_base_nt.hpp>
|
# include <boost/smart_ptr/detail/sp_counted_base_nt.hpp>
|
||||||
|
|
||||||
@@ -35,6 +41,12 @@
|
|||||||
#elif defined( BOOST_DISABLE_THREADS ) && !defined( BOOST_SP_ENABLE_THREADS ) && !defined( BOOST_DISABLE_WIN32 )
|
#elif defined( BOOST_DISABLE_THREADS ) && !defined( BOOST_SP_ENABLE_THREADS ) && !defined( BOOST_DISABLE_WIN32 )
|
||||||
# include <boost/smart_ptr/detail/sp_counted_base_nt.hpp>
|
# include <boost/smart_ptr/detail/sp_counted_base_nt.hpp>
|
||||||
|
|
||||||
|
#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__ )
|
#elif defined( __SNC__ )
|
||||||
# include <boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp>
|
# include <boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp>
|
||||||
|
|
||||||
@@ -56,7 +68,7 @@
|
|||||||
#elif defined( __GNUC__ ) && ( defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc ) ) && !defined(__PATHSCALE__) && !defined( _AIX )
|
#elif defined( __GNUC__ ) && ( defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc ) ) && !defined(__PATHSCALE__) && !defined( _AIX )
|
||||||
# include <boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp>
|
# 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>
|
# include <boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp>
|
||||||
|
|
||||||
#elif defined( BOOST_SP_HAS_SYNC )
|
#elif defined( BOOST_SP_HAS_SYNC )
|
||||||
@@ -79,4 +91,6 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#undef BOOST_SP_HAS_CLANG_C11_ATOMICS
|
||||||
|
|
||||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_HPP_INCLUDED
|
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_HPP_INCLUDED
|
||||||
|
149
include/boost/smart_ptr/detail/sp_counted_base_clang.hpp
Normal file
149
include/boost/smart_ptr/detail/sp_counted_base_clang.hpp
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CLANG_HPP_INCLUDED
|
||||||
|
#define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CLANG_HPP_INCLUDED
|
||||||
|
|
||||||
|
// MS compatible compilers support #pragma once
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// detail/sp_counted_base_clang.hpp - __c11 clang intrinsics
|
||||||
|
//
|
||||||
|
// Copyright (c) 2007, 2013, 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/detail/sp_typeinfo.hpp>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
typedef _Atomic( boost::int_least32_t ) atomic_int_least32_t;
|
||||||
|
|
||||||
|
inline void atomic_increment( atomic_int_least32_t * pw )
|
||||||
|
{
|
||||||
|
__c11_atomic_fetch_add( pw, 1, __ATOMIC_RELAXED );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline boost::int_least32_t atomic_decrement( atomic_int_least32_t * pw )
|
||||||
|
{
|
||||||
|
return __c11_atomic_fetch_sub( pw, 1, __ATOMIC_ACQ_REL );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline boost::int_least32_t atomic_conditional_increment( atomic_int_least32_t * pw )
|
||||||
|
{
|
||||||
|
// long r = *pw;
|
||||||
|
// if( r != 0 ) ++*pw;
|
||||||
|
// return r;
|
||||||
|
|
||||||
|
boost::int_least32_t r = __c11_atomic_load( pw, __ATOMIC_RELAXED );
|
||||||
|
|
||||||
|
for( ;; )
|
||||||
|
{
|
||||||
|
if( r == 0 )
|
||||||
|
{
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( __c11_atomic_compare_exchange_weak( pw, &r, r + 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED ) )
|
||||||
|
{
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic push
|
||||||
|
# pragma clang diagnostic ignored "-Wweak-vtables"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class sp_counted_base
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
sp_counted_base( sp_counted_base const & );
|
||||||
|
sp_counted_base & operator= ( sp_counted_base const & );
|
||||||
|
|
||||||
|
atomic_int_least32_t use_count_; // #shared
|
||||||
|
atomic_int_least32_t weak_count_; // #weak + (#shared != 0)
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
sp_counted_base()
|
||||||
|
{
|
||||||
|
__c11_atomic_init( &use_count_, 1 );
|
||||||
|
__c11_atomic_init( &weak_count_, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~sp_counted_base() // nothrow
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// dispose() is called when use_count_ drops to zero, to release
|
||||||
|
// the resources managed by *this.
|
||||||
|
|
||||||
|
virtual void dispose() = 0; // nothrow
|
||||||
|
|
||||||
|
// destroy() is called when weak_count_ drops to zero.
|
||||||
|
|
||||||
|
virtual void destroy() // nothrow
|
||||||
|
{
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||||
|
virtual void * get_untyped_deleter() = 0;
|
||||||
|
|
||||||
|
void add_ref_copy()
|
||||||
|
{
|
||||||
|
atomic_increment( &use_count_ );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool add_ref_lock() // true on success
|
||||||
|
{
|
||||||
|
return atomic_conditional_increment( &use_count_ ) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void release() // nothrow
|
||||||
|
{
|
||||||
|
if( atomic_decrement( &use_count_ ) == 1 )
|
||||||
|
{
|
||||||
|
dispose();
|
||||||
|
weak_release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void weak_add_ref() // nothrow
|
||||||
|
{
|
||||||
|
atomic_increment( &weak_count_ );
|
||||||
|
}
|
||||||
|
|
||||||
|
void weak_release() // nothrow
|
||||||
|
{
|
||||||
|
if( atomic_decrement( &weak_count_ ) == 1 )
|
||||||
|
{
|
||||||
|
destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long use_count() const // nothrow
|
||||||
|
{
|
||||||
|
return __c11_atomic_load( const_cast< atomic_int_least32_t* >( &use_count_ ), __ATOMIC_ACQUIRE );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CLANG_HPP_INCLUDED
|
@@ -78,7 +78,7 @@ public:
|
|||||||
boost::checked_delete( px_ );
|
boost::checked_delete( px_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_deleter( detail::sp_typeinfo const & )
|
virtual void * get_deleter( sp_typeinfo const & )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ public:
|
|||||||
del( ptr );
|
del( ptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_deleter( detail::sp_typeinfo const & ti )
|
virtual void * get_deleter( sp_typeinfo const & ti )
|
||||||
{
|
{
|
||||||
return ti == BOOST_SP_TYPEID(D)? &reinterpret_cast<char&>( del ): 0;
|
return ti == BOOST_SP_TYPEID(D)? &reinterpret_cast<char&>( del ): 0;
|
||||||
}
|
}
|
||||||
@@ -249,7 +249,7 @@ public:
|
|||||||
a2.deallocate( this, 1 );
|
a2.deallocate( this, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_deleter( detail::sp_typeinfo const & ti )
|
virtual void * get_deleter( sp_typeinfo const & ti )
|
||||||
{
|
{
|
||||||
return ti == BOOST_SP_TYPEID( D )? &reinterpret_cast<char&>( d_ ): 0;
|
return ti == BOOST_SP_TYPEID( D )? &reinterpret_cast<char&>( d_ ): 0;
|
||||||
}
|
}
|
||||||
|
40
include/boost/smart_ptr/detail/sp_disable_deprecated.hpp
Normal file
40
include/boost/smart_ptr/detail/sp_disable_deprecated.hpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef BOOST_SMART_PTR_DETAIL_SP_DISABLE_DEPRECATED_HPP_INCLUDED
|
||||||
|
#define BOOST_SMART_PTR_DETAIL_SP_DISABLE_DEPRECATED_HPP_INCLUDED
|
||||||
|
|
||||||
|
// MS compatible compilers support #pragma once
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// boost/smart_ptr/detail/sp_disable_deprecated.hpp
|
||||||
|
//
|
||||||
|
// Copyright 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/config.hpp>
|
||||||
|
|
||||||
|
#if defined( __GNUC__ ) && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || ( __cplusplus >= 201103L ) )
|
||||||
|
|
||||||
|
# if defined( BOOST_GCC )
|
||||||
|
|
||||||
|
# if BOOST_GCC >= 40600
|
||||||
|
# define BOOST_SP_DISABLE_DEPRECATED
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# elif defined( __clang__ ) && defined( __has_warning )
|
||||||
|
|
||||||
|
# if __has_warning( "-Wdeprecated-declarations" )
|
||||||
|
# define BOOST_SP_DISABLE_DEPRECATED
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_DISABLE_DEPRECATED_HPP_INCLUDED
|
@@ -25,6 +25,17 @@ namespace detail
|
|||||||
|
|
||||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||||
|
|
||||||
|
#if defined( BOOST_GCC ) && __GNUC__ * 100 + __GNUC_MINOR__ <= 404
|
||||||
|
|
||||||
|
// GCC 4.4 supports an outdated version of rvalue references and creates a copy of the forwarded object.
|
||||||
|
// This results in warnings 'returning reference to temporary'. Therefore we use a special version similar to std::forward.
|
||||||
|
template< class T > T&& sp_forward( T && t ) BOOST_NOEXCEPT
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
template< class T > T&& sp_forward( T & t ) BOOST_NOEXCEPT
|
template< class T > T&& sp_forward( T & t ) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return static_cast< T&& >( t );
|
return static_cast< T&& >( t );
|
||||||
@@ -32,6 +43,8 @@ template< class T > T&& sp_forward( T & t ) BOOST_NOEXCEPT
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@@ -111,6 +111,17 @@ extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long
|
|||||||
extern "C" long __cdecl _InterlockedExchange( long volatile *, long );
|
extern "C" long __cdecl _InterlockedExchange( long volatile *, long );
|
||||||
extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long );
|
extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long );
|
||||||
|
|
||||||
|
# if defined( BOOST_MSVC ) && BOOST_MSVC == 1310
|
||||||
|
//From MSDN, Visual Studio .NET 2003 spedific: To declare one of the interlocked functions
|
||||||
|
//for use as an intrinsic, the function must be declared with the leading underscore and
|
||||||
|
//the new function must appear in a #pragma intrinsic statement.
|
||||||
|
# pragma intrinsic( _InterlockedIncrement )
|
||||||
|
# pragma intrinsic( _InterlockedDecrement )
|
||||||
|
# pragma intrinsic( _InterlockedCompareExchange )
|
||||||
|
# pragma intrinsic( _InterlockedExchange )
|
||||||
|
# pragma intrinsic( _InterlockedExchangeAdd )
|
||||||
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement
|
# define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement
|
||||||
|
@@ -26,7 +26,7 @@ namespace boost
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
#if defined( __clang__ ) && !defined( _LIBCPP_VERSION ) && !defined( BOOST_NO_CXX11_DECLTYPE )
|
#if !defined( BOOST_NO_CXX11_DECLTYPE ) && ( ( defined( __clang__ ) && !defined( _LIBCPP_VERSION ) ) || defined( __INTEL_COMPILER ) )
|
||||||
|
|
||||||
typedef decltype(nullptr) sp_nullptr_t;
|
typedef decltype(nullptr) sp_nullptr_t;
|
||||||
|
|
||||||
|
@@ -43,6 +43,9 @@
|
|||||||
#elif defined( BOOST_SP_USE_PTHREADS )
|
#elif defined( BOOST_SP_USE_PTHREADS )
|
||||||
# include <boost/smart_ptr/detail/spinlock_pt.hpp>
|
# 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__ )
|
#elif defined(__GNUC__) && defined( __arm__ ) && !defined( __thumb__ )
|
||||||
# include <boost/smart_ptr/detail/spinlock_gcc_arm.hpp>
|
# include <boost/smart_ptr/detail/spinlock_gcc_arm.hpp>
|
||||||
|
|
||||||
|
@@ -82,6 +82,7 @@ public:
|
|||||||
{
|
{
|
||||||
__asm__ __volatile__( BOOST_SP_ARM_BARRIER ::: "memory" );
|
__asm__ __volatile__( BOOST_SP_ARM_BARRIER ::: "memory" );
|
||||||
*const_cast< int volatile* >( &v_ ) = 0;
|
*const_cast< int volatile* >( &v_ ) = 0;
|
||||||
|
__asm__ __volatile__( BOOST_SP_ARM_BARRIER ::: "memory" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@@ -31,7 +31,7 @@ namespace boost
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
template< int I > class spinlock_pool
|
template< int M > class spinlock_pool
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ public:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template< int I > spinlock spinlock_pool< I >::pool_[ 41 ] =
|
template< int M > spinlock spinlock_pool< M >::pool_[ 41 ] =
|
||||||
{
|
{
|
||||||
BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
|
BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
|
||||||
BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
|
BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
|
||||||
|
@@ -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
|
|
@@ -60,7 +60,16 @@ namespace detail
|
|||||||
{
|
{
|
||||||
|
|
||||||
#if !defined( BOOST_USE_WINDOWS_H ) && !BOOST_PLAT_WINDOWS_RUNTIME
|
#if !defined( BOOST_USE_WINDOWS_H ) && !BOOST_PLAT_WINDOWS_RUNTIME
|
||||||
|
#if !BOOST_COMP_CLANG || !defined __MINGW32__
|
||||||
extern "C" void __stdcall Sleep( unsigned long ms );
|
extern "C" void __stdcall Sleep( unsigned long ms );
|
||||||
|
#else
|
||||||
|
#include <_mingw.h>
|
||||||
|
#if !defined __MINGW64_VERSION_MAJOR
|
||||||
|
extern "C" void __stdcall Sleep( unsigned long ms );
|
||||||
|
#else
|
||||||
|
extern "C" __declspec(dllimport) void __stdcall Sleep( unsigned long ms );
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline void yield( unsigned k )
|
inline void yield( unsigned k )
|
||||||
@@ -98,7 +107,13 @@ inline void yield( unsigned k )
|
|||||||
|
|
||||||
#elif defined( BOOST_HAS_PTHREADS )
|
#elif defined( BOOST_HAS_PTHREADS )
|
||||||
|
|
||||||
|
#ifndef _AIX
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#else
|
||||||
|
// AIX's sched.h defines ::var which sometimes conflicts with Lambda's var
|
||||||
|
extern "C" int sched_yield(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
// enable_shared_from_raw.hpp
|
// enable_shared_from_raw.hpp
|
||||||
//
|
//
|
||||||
// Copyright 2002, 2009 Peter Dimov
|
// Copyright 2002, 2009, 2014 Peter Dimov
|
||||||
// Copyright 2008-2009 Frank Mori Hess
|
// Copyright 2008-2009 Frank Mori Hess
|
||||||
//
|
//
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
@@ -53,7 +53,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void init_weak_once() const
|
void init_if_expired() const
|
||||||
{
|
{
|
||||||
if( weak_this_.expired() )
|
if( weak_this_.expired() )
|
||||||
{
|
{
|
||||||
@@ -62,6 +62,15 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_if_empty() const
|
||||||
|
{
|
||||||
|
if( weak_this_._empty() )
|
||||||
|
{
|
||||||
|
shared_this_.reset( static_cast<void*>(0), detail::esft2_deleter_wrapper() );
|
||||||
|
weak_this_ = shared_this_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||||
public:
|
public:
|
||||||
#else
|
#else
|
||||||
@@ -72,20 +81,30 @@ private:
|
|||||||
template< class X, class Y > friend inline void detail::sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe );
|
template< class X, class Y > friend inline void detail::sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
shared_ptr<void> shared_from_this()
|
shared_ptr<void const volatile> shared_from_this() const
|
||||||
{
|
{
|
||||||
init_weak_once();
|
init_if_expired();
|
||||||
return shared_ptr<void>( weak_this_ );
|
return shared_ptr<void const volatile>( weak_this_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<const void> shared_from_this() const
|
shared_ptr<void const volatile> shared_from_this() const volatile
|
||||||
{
|
{
|
||||||
init_weak_once();
|
return const_cast< enable_shared_from_raw const * >( this )->shared_from_this();
|
||||||
return shared_ptr<const void>( weak_this_ );
|
}
|
||||||
|
|
||||||
|
weak_ptr<void const volatile> weak_from_this() const
|
||||||
|
{
|
||||||
|
init_if_empty();
|
||||||
|
return weak_this_;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_ptr<void const volatile> weak_from_this() const volatile
|
||||||
|
{
|
||||||
|
return const_cast< enable_shared_from_raw const * >( this )->weak_from_this();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: invoked automatically by shared_ptr; do not call
|
// 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 );
|
BOOST_ASSERT( ppx != 0 );
|
||||||
|
|
||||||
@@ -107,9 +126,11 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mutable weak_ptr<void> weak_this_;
|
mutable weak_ptr<void const volatile> weak_this_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable shared_ptr<void> shared_this_;
|
|
||||||
|
mutable shared_ptr<void const volatile> shared_this_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -124,7 +145,7 @@ boost::weak_ptr<T> weak_from_raw(T *p)
|
|||||||
{
|
{
|
||||||
BOOST_ASSERT(p != 0);
|
BOOST_ASSERT(p != 0);
|
||||||
boost::weak_ptr<T> result;
|
boost::weak_ptr<T> result;
|
||||||
result._internal_aliasing_assign(p->enable_shared_from_raw::weak_this_, p);
|
result._internal_aliasing_assign(p->enable_shared_from_raw::weak_from_this(), p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,6 +58,16 @@ public:
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
weak_ptr<T> weak_from_this() BOOST_NOEXCEPT
|
||||||
|
{
|
||||||
|
return weak_this_;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_ptr<T const> weak_from_this() const BOOST_NOEXCEPT
|
||||||
|
{
|
||||||
|
return weak_this_;
|
||||||
|
}
|
||||||
|
|
||||||
public: // actually private, but avoids compiler template friendship issues
|
public: // actually private, but avoids compiler template friendship issues
|
||||||
|
|
||||||
// Note: invoked automatically by shared_ptr; do not call
|
// Note: invoked automatically by shared_ptr; do not call
|
||||||
|
@@ -59,7 +59,7 @@ public:
|
|||||||
|
|
||||||
typedef T element_type;
|
typedef T element_type;
|
||||||
|
|
||||||
intrusive_ptr() BOOST_NOEXCEPT : px( 0 )
|
BOOST_CONSTEXPR intrusive_ptr() BOOST_NOEXCEPT : px( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +122,30 @@ public:
|
|||||||
return *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
|
#endif
|
||||||
|
|
||||||
intrusive_ptr & operator=(intrusive_ptr const & rhs)
|
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
|
static unsigned int decrement(boost::detail::atomic_count& counter) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return --counter;
|
return static_cast< unsigned int >(--counter);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -13,6 +13,8 @@
|
|||||||
// for documentation.
|
// for documentation.
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#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/shared_ptr.hpp>
|
||||||
#include <boost/smart_ptr/detail/sp_forward.hpp>
|
#include <boost/smart_ptr/detail/sp_forward.hpp>
|
||||||
#include <boost/type_traits/type_with_alignment.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 );
|
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
|
// C++03 version
|
||||||
|
|
||||||
template< class T, class A1 >
|
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 ) );
|
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();
|
void * pv = pd->address();
|
||||||
|
|
||||||
::new( pv ) T( a1 );
|
::new( pv ) T(
|
||||||
|
boost::forward<A1>( a1 )
|
||||||
|
);
|
||||||
|
|
||||||
pd->set_initialized();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
void * pv = pd->address();
|
||||||
|
|
||||||
::new( pv ) T( a1 );
|
::new( pv ) T(
|
||||||
|
boost::forward<A1>( a1 )
|
||||||
|
);
|
||||||
|
|
||||||
pd->set_initialized();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
void * pv = pd->address();
|
||||||
|
|
||||||
::new( pv ) T( a1, a2 );
|
::new( pv ) T(
|
||||||
|
boost::forward<A1>( a1 ),
|
||||||
|
boost::forward<A2>( a2 )
|
||||||
|
);
|
||||||
|
|
||||||
pd->set_initialized();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
void * pv = pd->address();
|
||||||
|
|
||||||
::new( pv ) T( a1, a2 );
|
::new( pv ) T(
|
||||||
|
boost::forward<A1>( a1 ),
|
||||||
|
boost::forward<A2>( a2 )
|
||||||
|
);
|
||||||
|
|
||||||
pd->set_initialized();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 ) );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 >
|
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 );
|
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();
|
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();
|
pd->set_initialized();
|
||||||
|
|
||||||
T * pt2 = static_cast< T* >( pv );
|
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 );
|
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 )
|
#endif // !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||||
|
|
||||||
#undef BOOST_SP_MSD
|
#undef BOOST_SP_MSD
|
||||||
|
@@ -1,15 +1,105 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
||||||
#define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
#define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
||||||
|
|
||||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_object.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 n)
|
||||||
|
{
|
||||||
|
return std::unique_ptr<T>(new
|
||||||
|
typename detail::up_element<T>::type[n]());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename detail::up_if_array<T>::type
|
||||||
|
make_unique_noinit(std::size_t n)
|
||||||
|
{
|
||||||
|
return std::unique_ptr<T>(new
|
||||||
|
typename detail::up_element<T>::type[n]);
|
||||||
|
}
|
||||||
|
} /* boost */
|
||||||
|
|
||||||
#endif
|
#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
|
|
@@ -15,12 +15,18 @@
|
|||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/checked_delete.hpp>
|
#include <boost/checked_delete.hpp>
|
||||||
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||||
|
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
|
||||||
#include <boost/detail/workaround.hpp>
|
#include <boost/detail/workaround.hpp>
|
||||||
|
|
||||||
#ifndef BOOST_NO_AUTO_PTR
|
#ifndef BOOST_NO_AUTO_PTR
|
||||||
# include <memory> // for std::auto_ptr
|
# include <memory> // for std::auto_ptr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -154,4 +160,8 @@ template<class T> inline T * get_pointer(scoped_ptr<T> const & p) BOOST_NOEXCEPT
|
|||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED
|
#endif // #ifndef BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include <boost/detail/workaround.hpp>
|
#include <boost/detail/workaround.hpp>
|
||||||
#include <boost/smart_ptr/detail/sp_convertible.hpp>
|
#include <boost/smart_ptr/detail/sp_convertible.hpp>
|
||||||
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||||
|
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
|
||||||
|
|
||||||
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
|
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
|
||||||
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
|
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
|
||||||
@@ -47,6 +48,11 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -55,6 +61,13 @@ template<class T> class weak_ptr;
|
|||||||
template<class T> class enable_shared_from_this;
|
template<class T> class enable_shared_from_this;
|
||||||
class enable_shared_from_raw;
|
class enable_shared_from_raw;
|
||||||
|
|
||||||
|
namespace movelib
|
||||||
|
{
|
||||||
|
|
||||||
|
template< class T, class D > class unique_ptr;
|
||||||
|
|
||||||
|
} // namespace movelib
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -495,6 +508,17 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template< class Y, class D >
|
||||||
|
shared_ptr( boost::movelib::unique_ptr< Y, D > r ): px( r.get() ), pn()
|
||||||
|
{
|
||||||
|
boost::detail::sp_assert_convertible< Y, T >();
|
||||||
|
|
||||||
|
typename boost::movelib::unique_ptr< Y, D >::pointer tmp = r.get();
|
||||||
|
pn = boost::detail::shared_count( r );
|
||||||
|
|
||||||
|
boost::detail::sp_deleter_construct( this, tmp );
|
||||||
|
}
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
|
|
||||||
shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
|
shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
|
||||||
@@ -556,6 +580,27 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<class Y, class D>
|
||||||
|
shared_ptr & operator=( boost::movelib::unique_ptr<Y, D> r )
|
||||||
|
{
|
||||||
|
// this_type( static_cast< unique_ptr<Y, D> && >( r ) ).swap( *this );
|
||||||
|
|
||||||
|
boost::detail::sp_assert_convertible< Y, T >();
|
||||||
|
|
||||||
|
typename boost::movelib::unique_ptr< Y, D >::pointer p = r.get();
|
||||||
|
|
||||||
|
shared_ptr tmp;
|
||||||
|
|
||||||
|
tmp.px = p;
|
||||||
|
tmp.pn = boost::detail::shared_count( r );
|
||||||
|
|
||||||
|
boost::detail::sp_deleter_construct( &tmp, p );
|
||||||
|
|
||||||
|
tmp.swap( *this );
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// Move support
|
// Move support
|
||||||
|
|
||||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||||
@@ -597,6 +642,14 @@ public:
|
|||||||
return *this;
|
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
|
#endif
|
||||||
|
|
||||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||||
@@ -635,6 +688,15 @@ public:
|
|||||||
this_type( r, p ).swap( *this );
|
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)
|
// never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
|
||||||
typename boost::detail::sp_dereference< T >::type operator* () const
|
typename boost::detail::sp_dereference< T >::type operator* () const
|
||||||
{
|
{
|
||||||
@@ -655,7 +717,7 @@ public:
|
|||||||
BOOST_ASSERT( px != 0 );
|
BOOST_ASSERT( px != 0 );
|
||||||
BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
|
BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
|
||||||
|
|
||||||
return px[ i ];
|
return static_cast< typename boost::detail::sp_array_access< T >::type >( px[ i ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
element_type * get() const BOOST_NOEXCEPT
|
element_type * get() const BOOST_NOEXCEPT
|
||||||
@@ -893,7 +955,7 @@ class esft2_deleter_wrapper
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
shared_ptr<void> deleter_;
|
shared_ptr<void const volatile> deleter_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -1020,9 +1082,13 @@ template< class T > struct hash;
|
|||||||
|
|
||||||
template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT
|
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
|
} // namespace boost
|
||||||
|
|
||||||
|
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
|
#endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
|
||||||
|
22
meta/libraries.json
Normal file
22
meta/libraries.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"key": "smart_ptr",
|
||||||
|
"name": "Smart Ptr",
|
||||||
|
"authors": [
|
||||||
|
"Greg Colvin",
|
||||||
|
"Beman Dawes",
|
||||||
|
"Peter Dimov",
|
||||||
|
"Darin Adler",
|
||||||
|
"Glen Fernandes"
|
||||||
|
],
|
||||||
|
"description": "Smart pointer class templates.",
|
||||||
|
"documentation": "smart_ptr.htm",
|
||||||
|
"std": [
|
||||||
|
"tr1"
|
||||||
|
],
|
||||||
|
"category": [
|
||||||
|
"Memory"
|
||||||
|
],
|
||||||
|
"maintainers": [
|
||||||
|
"Peter Dimov <pdimov -at- pdimov.com>"
|
||||||
|
]
|
||||||
|
}
|
@@ -2,16 +2,16 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>pointer_cast</title>
|
<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>
|
</head>
|
||||||
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
||||||
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
<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>
|
<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>)
|
<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
|
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>
|
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>
|
<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>
|
<h2><a name="rationale">Rationale</a></h2>
|
||||||
<P>Boost smart pointers usually overload those functions to provide a mechanism to
|
<P>Boost smart pointers usually overload those functions to provide a mechanism to
|
||||||
emulate pointers casts. For example, <code>boost::shared_ptr<...></code> implements
|
emulate pointers casts. For example, <code>boost::shared_ptr<...></code> implements
|
||||||
@@ -20,15 +20,15 @@
|
|||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
shared_ptr<T> static_pointer_cast(shared_ptr<U> const &r);
|
shared_ptr<T> static_pointer_cast(shared_ptr<U> const &r);
|
||||||
</pre>
|
</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>,
|
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>
|
<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 raw pointers, <code>std::shared_ptr</code> and <code>std::unique_ptr</code>. This way when developing
|
||||||
for example, memory managers or shared memory compatible classes, the same code
|
pointer type independent classes, for example, memory managers or shared memory compatible classes, the same
|
||||||
can be used for raw and smart pointers.</p>
|
code can be used for raw and smart pointers.</p>
|
||||||
<H2><A name="synopsis">Synopsis</A></H2>
|
<h2><a name="synopsis">Synopsis</a></h2>
|
||||||
<BLOCKQUOTE>
|
<blockquote>
|
||||||
<PRE>
|
<pre>
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
@@ -47,14 +47,92 @@ template<class T, class U>
|
|||||||
inline T* reinterpret_pointer_cast(U *ptr)
|
inline T* reinterpret_pointer_cast(U *ptr)
|
||||||
{ return reinterpret_cast<T*>(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
|
} // namespace boost
|
||||||
</PRE>
|
</pre>
|
||||||
</BLOCKQUOTE>
|
</blockquote>
|
||||||
<P>As you can see from the above synopsis, the pointer cast functions are just
|
<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>
|
wrappers around standard C++ cast operators.</p>
|
||||||
<H2><A name="example">Example</A></H2>
|
|
||||||
<BLOCKQUOTE>
|
<p>The pointer casts for <code>std::shared_ptr</code> are aliases of the corresponding standard
|
||||||
<PRE>
|
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/pointer_cast.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
@@ -79,28 +157,27 @@ void check_if_it_is_derived(const BasePtr &ptr)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
<I>// Create a raw and a shared_ptr</I>
|
<em>// Create a raw and a shared_ptr</em>
|
||||||
|
|
||||||
base *ptr = new derived;
|
base *ptr = new derived;
|
||||||
boost::shared_ptr<base> sptr(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(ptr);
|
||||||
check_if_it_is_derived(sptr);
|
check_if_it_is_derived(sptr);
|
||||||
|
|
||||||
// <EM>Ok!</EM>
|
<em>// Ok!</em>
|
||||||
|
|
||||||
delete ptr;
|
delete ptr;
|
||||||
return 0;
|
return 0;
|
||||||
}</PRE>
|
}</pre>
|
||||||
</BLOCKQUOTE>
|
</blockquote>
|
||||||
<P>The example demonstrates how the generic pointer casts help us create pointer
|
<p>The example demonstrates how the generic pointer casts help us create pointer
|
||||||
independent code.</P>
|
independent code.</p>
|
||||||
<hr>
|
<hr />
|
||||||
<p>$Date$</p>
|
|
||||||
<p>Copyright 2005 Ion Gazta<74>aga. Use, modification, and distribution are subject to
|
<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">
|
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>
|
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>
|
</body>
|
||||||
</html>
|
</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_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="#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);
|
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
|
shared_ptr<T> <a href="#dynamic_pointer_cast" >dynamic_pointer_cast</a>(shared_ptr<U> const & r); // never throws
|
||||||
|
|
||||||
template<class T, class U>
|
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>
|
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);
|
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>Postconditions:</b> <code>get() == p && use_count() == r.use_count()</code>.</p>
|
||||||
<p><b>Throws:</b> nothing.</p>
|
<p><b>Throws:</b> nothing.</p>
|
||||||
</blockquote>
|
</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>
|
<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>
|
<pre>template<class Y> explicit shared_ptr(<a href="weak_ptr.htm" >weak_ptr</a><Y> const & r);</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
|
@@ -29,11 +29,13 @@ import testing ;
|
|||||||
[ compile-fail shared_ptr_compare_fail.cpp ]
|
[ compile-fail shared_ptr_compare_fail.cpp ]
|
||||||
[ run shared_ptr_alloc2_test.cpp ]
|
[ run shared_ptr_alloc2_test.cpp ]
|
||||||
[ run pointer_cast_test.cpp ]
|
[ run pointer_cast_test.cpp ]
|
||||||
|
[ run cpp11_pointer_cast_test.cpp ]
|
||||||
[ compile pointer_to_other_test.cpp ]
|
[ compile pointer_to_other_test.cpp ]
|
||||||
[ run auto_ptr_rv_test.cpp ]
|
[ run auto_ptr_rv_test.cpp ]
|
||||||
[ run shared_ptr_alias_test.cpp ]
|
[ run shared_ptr_alias_test.cpp ]
|
||||||
[ run shared_ptr_rv_test.cpp ]
|
[ run shared_ptr_rv_test.cpp ]
|
||||||
[ run shared_ptr_move_test.cpp ]
|
[ run shared_ptr_move_test.cpp ]
|
||||||
|
[ run shared_ptr_alias_move_test.cpp ]
|
||||||
[ compile-fail shared_ptr_pv_fail.cpp ]
|
[ compile-fail shared_ptr_pv_fail.cpp ]
|
||||||
[ run sp_unary_addr_test.cpp ]
|
[ run sp_unary_addr_test.cpp ]
|
||||||
[ compile-fail scoped_ptr_eq_fail.cpp ]
|
[ compile-fail scoped_ptr_eq_fail.cpp ]
|
||||||
@@ -46,6 +48,7 @@ import testing ;
|
|||||||
[ run spinlock_try_test.cpp : : : <threading>multi : spinlock_try_test.mt ]
|
[ run spinlock_try_test.cpp : : : <threading>multi : spinlock_try_test.mt ]
|
||||||
[ run spinlock_pool_test.cpp ]
|
[ run spinlock_pool_test.cpp ]
|
||||||
[ run make_shared_test.cpp ]
|
[ run make_shared_test.cpp ]
|
||||||
|
[ run make_shared_move_emulation_test.cpp ]
|
||||||
[ run make_shared_perfect_forwarding_test.cpp ]
|
[ run make_shared_perfect_forwarding_test.cpp ]
|
||||||
[ run shared_ptr_convertible_test.cpp ]
|
[ run shared_ptr_convertible_test.cpp ]
|
||||||
[ run wp_convertible_test.cpp ]
|
[ run wp_convertible_test.cpp ]
|
||||||
@@ -60,8 +63,6 @@ import testing ;
|
|||||||
[ run sp_recursive_assign2_test.cpp ]
|
[ run sp_recursive_assign2_test.cpp ]
|
||||||
[ run sp_recursive_assign_rv_test.cpp ]
|
[ run sp_recursive_assign_rv_test.cpp ]
|
||||||
[ run sp_recursive_assign2_rv_test.cpp ]
|
[ run sp_recursive_assign2_rv_test.cpp ]
|
||||||
[ run esft_constructor_test.cpp ]
|
|
||||||
[ run enable_shared_from_raw_test.cpp ]
|
|
||||||
[ compile-fail auto_ptr_lv_fail.cpp ]
|
[ compile-fail auto_ptr_lv_fail.cpp ]
|
||||||
[ run atomic_count_test2.cpp ]
|
[ run atomic_count_test2.cpp ]
|
||||||
[ run sp_typeinfo_test.cpp ]
|
[ run sp_typeinfo_test.cpp ]
|
||||||
@@ -163,5 +164,42 @@ import testing ;
|
|||||||
[ run make_unique_array_test.cpp ]
|
[ run make_unique_array_test.cpp ]
|
||||||
[ run make_unique_array_noinit_test.cpp ]
|
[ run make_unique_array_noinit_test.cpp ]
|
||||||
[ run make_unique_array_throws_test.cpp ]
|
[ run make_unique_array_throws_test.cpp ]
|
||||||
|
|
||||||
|
[ run shared_from_raw_test.cpp ]
|
||||||
|
[ run shared_from_raw_test2.cpp ]
|
||||||
|
[ run shared_from_raw_test3.cpp ]
|
||||||
|
[ run shared_from_raw_test4.cpp ]
|
||||||
|
[ run shared_from_raw_test5.cpp ]
|
||||||
|
[ run shared_from_raw_test6.cpp ]
|
||||||
|
|
||||||
|
[ run weak_from_raw_test.cpp ]
|
||||||
|
[ run weak_from_raw_test2.cpp ]
|
||||||
|
[ run weak_from_raw_test3.cpp ]
|
||||||
|
[ run weak_from_raw_test4.cpp ]
|
||||||
|
[ run weak_from_raw_test5.cpp ]
|
||||||
|
|
||||||
|
[ compile sp_explicit_inst_test.cpp ]
|
||||||
|
|
||||||
|
[ run weak_from_this_test.cpp ]
|
||||||
|
[ 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 ]
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@@ -1,43 +1,38 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
|
||||||
|
struct tag { };
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class creator {
|
class creator {
|
||||||
public:
|
public:
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
creator() {
|
creator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
creator(const creator<U>&) {
|
creator(const creator<U>&) {
|
||||||
}
|
}
|
||||||
|
|
||||||
T* allocate(std::size_t size) {
|
T* allocate(std::size_t size) {
|
||||||
void* p1 = ::operator new(size * sizeof(T));
|
void* p = ::operator new(size * sizeof(T));
|
||||||
return static_cast<T*>(p1);
|
return static_cast<T*>(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate(T* memory, std::size_t) {
|
void deallocate(T* memory, std::size_t) {
|
||||||
void* p1 = memory;
|
void* p = memory;
|
||||||
::operator delete(p1);
|
::operator delete(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
void construct(U* memory) {
|
void construct(U* memory) {
|
||||||
void* p1 = memory;
|
void* p = memory;
|
||||||
::new(p1) U();
|
::new(p) U(tag());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
void destroy(U* memory) {
|
void destroy(U* memory) {
|
||||||
memory->~U();
|
memory->~U();
|
||||||
@@ -45,116 +40,88 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
friend class creator<type>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
static const type object;
|
explicit type(tag) {
|
||||||
|
|
||||||
protected:
|
|
||||||
explicit type() {
|
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
type(const type&) {
|
type(const type&) {
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int type::instances;
|
unsigned int type::instances = 0;
|
||||||
const type type::object;
|
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
BOOST_TEST(type::instances == 1);
|
{
|
||||||
|
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(creator<void>(), 3);
|
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(creator<void>(), 3);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(type::instances == 4);
|
BOOST_TEST(type::instances == 3);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 1);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(creator<void>());
|
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(creator<void>());
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(type::instances == 4);
|
BOOST_TEST(type::instances == 3);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
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::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(creator<void>(), 2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(type::instances == 5);
|
BOOST_TEST(type::instances == 4);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
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::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(creator<void>());
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(type::instances == 5);
|
BOOST_TEST(type::instances == 4);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
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::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(creator<void>(), 3);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(type::instances == 4);
|
BOOST_TEST(type::instances == 3);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
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::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(creator<void>());
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(type::instances == 4);
|
BOOST_TEST(type::instances == 3);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
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::shared_ptr<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(creator<void>(), 2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(type::instances == 5);
|
BOOST_TEST(type::instances == 4);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 1);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[2][2]> a1 = boost::allocate_shared<const type[2][2]>(creator<void>());
|
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.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
BOOST_TEST(type::instances == 5);
|
BOOST_TEST(type::instances == 4);
|
||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 1);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@@ -1,28 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
|
||||||
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
|
|
||||||
class type
|
class type
|
||||||
: public boost::enable_shared_from_this<type> {
|
: public boost::enable_shared_from_this<type> {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -30,7 +27,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
||||||
@@ -41,7 +39,6 @@ int main() {
|
|||||||
BOOST_TEST(type::instances == 3);
|
BOOST_TEST(type::instances == 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
|
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
|
||||||
@@ -52,6 +49,5 @@ int main() {
|
|||||||
BOOST_TEST(type::instances == 3);
|
BOOST_TEST(type::instances == 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
#include <boost/type_traits/alignment_of.hpp>
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -30,7 +27,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared_noinit<int[]>(std::allocator<int>(), 3);
|
boost::shared_ptr<int[]> a1 = boost::allocate_shared_noinit<int[]>(std::allocator<int>(), 3);
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -38,7 +36,6 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[3]> a1 = boost::allocate_shared_noinit<int[3]>(std::allocator<int>());
|
boost::shared_ptr<int[3]> a1 = boost::allocate_shared_noinit<int[3]>(std::allocator<int>());
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -46,19 +43,16 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared_noinit<int[][2]>(std::allocator<int>(), 2);
|
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared_noinit<int[][2]>(std::allocator<int>(), 2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared_noinit<int[2][2]>(std::allocator<int>());
|
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.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared_noinit<const int[]>(std::allocator<int>(), 3);
|
boost::shared_ptr<const int[]> a1 = boost::allocate_shared_noinit<const int[]>(std::allocator<int>(), 3);
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -66,7 +60,6 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared_noinit<const int[3]>(std::allocator<int>());
|
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared_noinit<const int[3]>(std::allocator<int>());
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -74,20 +67,16 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared_noinit<const int[][2]>(std::allocator<int>(), 2);
|
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.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared_noinit<const int[2][2]>(std::allocator<int>());
|
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.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
|
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -99,8 +88,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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>());
|
boost::shared_ptr<type[3]> a1 = boost::allocate_shared_noinit<type[3]>(std::allocator<type>());
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -112,8 +99,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<type[][2]> a1 = boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -122,8 +107,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<type[2][2]> a1 = boost::allocate_shared_noinit<type[2][2]>(std::allocator<type>());
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -132,8 +115,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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);
|
boost::shared_ptr<const type[]> a1 = boost::allocate_shared_noinit<const type[]>(std::allocator<type>(), 3);
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -144,8 +125,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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>());
|
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared_noinit<const type[3]>(std::allocator<type>());
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -156,8 +135,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::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.get() != 0);
|
||||||
@@ -166,8 +143,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::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.get() != 0);
|
||||||
@@ -176,6 +151,5 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
#include <boost/type_traits/alignment_of.hpp>
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -30,7 +27,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 3);
|
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 3);
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -41,7 +39,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[3]> a1 = boost::allocate_shared<int[3]>(std::allocator<int>());
|
boost::shared_ptr<int[3]> a1 = boost::allocate_shared<int[3]>(std::allocator<int>());
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -52,7 +49,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2);
|
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -62,7 +58,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>());
|
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>());
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -72,7 +67,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 3);
|
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 3);
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -83,7 +77,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared<const int[3]>(std::allocator<int>());
|
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared<const int[3]>(std::allocator<int>());
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -94,7 +87,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 2);
|
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.get() != 0);
|
||||||
@@ -104,7 +96,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>());
|
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.get() != 0);
|
||||||
@@ -114,8 +105,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -127,8 +116,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>());
|
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>());
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -140,8 +127,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -150,8 +135,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(std::allocator<type>());
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -160,8 +143,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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);
|
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 3);
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -172,8 +153,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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>());
|
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(std::allocator<type>());
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -184,8 +163,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(std::allocator<type>(), 2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -194,8 +171,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::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.get() != 0);
|
||||||
@@ -204,6 +179,5 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,29 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
if (instances == 5) {
|
if (instances == 5) {
|
||||||
throw true;
|
throw true;
|
||||||
}
|
}
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -31,70 +28,55 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
BOOST_TEST(type::instances == 0);
|
{
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared<type[]>(std::allocator<type>(), 6);
|
boost::allocate_shared<type[]>(std::allocator<type>(), 6);
|
||||||
BOOST_ERROR("allocate_shared did not throw");
|
BOOST_ERROR("allocate_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared<type[][2]>(std::allocator<type>(), 3);
|
boost::allocate_shared<type[][2]>(std::allocator<type>(), 3);
|
||||||
BOOST_ERROR("allocate_shared did not throw");
|
BOOST_ERROR("allocate_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared<type[6]>(std::allocator<type>());
|
boost::allocate_shared<type[6]>(std::allocator<type>());
|
||||||
BOOST_ERROR("allocate_shared did not throw");
|
BOOST_ERROR("allocate_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared<type[3][2]>(std::allocator<type>());
|
boost::allocate_shared<type[3][2]>(std::allocator<type>());
|
||||||
BOOST_ERROR("allocate_shared did not throw");
|
BOOST_ERROR("allocate_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 6);
|
boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 6);
|
||||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 3);
|
boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 3);
|
||||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared_noinit<type[6]>(std::allocator<type>());
|
boost::allocate_shared_noinit<type[6]>(std::allocator<type>());
|
||||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::allocate_shared_noinit<type[3][2]>(std::allocator<type>());
|
boost::allocate_shared_noinit<type[3][2]>(std::allocator<type>());
|
||||||
BOOST_ERROR("allocate_shared_noinit did not throw");
|
BOOST_ERROR("allocate_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.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>
|
|
||||||
|
|
||||||
int main() {
|
Distributed under the Boost Software
|
||||||
|
License, Version 1.0.
|
||||||
|
http://boost.org/LICENSE_1_0.txt
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 4, 1);
|
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 4, 1);
|
||||||
BOOST_TEST(a1[0] == 1);
|
BOOST_TEST(a1[0] == 1);
|
||||||
@@ -17,7 +18,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), 1);
|
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), 1);
|
||||||
BOOST_TEST(a1[0] == 1);
|
BOOST_TEST(a1[0] == 1);
|
||||||
@@ -25,7 +25,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 4, 1);
|
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 4, 1);
|
||||||
BOOST_TEST(a1[0] == 1);
|
BOOST_TEST(a1[0] == 1);
|
||||||
@@ -33,7 +32,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[4]> a1 = boost::allocate_shared<const int[4]>(std::allocator<int>(), 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[0] == 1);
|
||||||
@@ -41,6 +39,5 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.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>
|
|
||||||
|
|
||||||
int main() {
|
Distributed under the Boost Software
|
||||||
|
License, Version 1.0.
|
||||||
|
http://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)
|
#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::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2, {0, 1});
|
||||||
@@ -18,7 +19,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), { 0, 1 });
|
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][0] == 0);
|
||||||
@@ -26,7 +26,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 2, { 0, 1 });
|
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][0] == 0);
|
||||||
@@ -34,7 +33,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>(), { 0, 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][0] == 0);
|
||||||
@@ -43,6 +41,5 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -12,8 +12,12 @@ struct X
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class T> void f( T & /*t*/ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
boost::shared_ptr<X> px( new X );
|
boost::shared_ptr<X> px( new X );
|
||||||
px[ 0 ];
|
f( px[ 0 ] );
|
||||||
}
|
}
|
||||||
|
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
|
@@ -143,6 +143,18 @@ int main()
|
|||||||
BOOST_TEST( N::base::instances == 0 );
|
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::intrusive_ptr<X> p( new X );
|
||||||
BOOST_TEST( N::base::instances == 1 );
|
BOOST_TEST( N::base::instances == 1 );
|
||||||
@@ -170,6 +182,33 @@ int main()
|
|||||||
BOOST_TEST( N::base::instances == 0 );
|
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();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,28 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/enable_shared_from_this.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
|
class type
|
||||||
: public boost::enable_shared_from_this<type> {
|
: public boost::enable_shared_from_this<type> {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -30,7 +27,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
||||||
@@ -41,7 +39,6 @@ int main() {
|
|||||||
BOOST_TEST(type::instances == 3);
|
BOOST_TEST(type::instances == 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
||||||
@@ -52,6 +49,5 @@ int main() {
|
|||||||
BOOST_TEST(type::instances == 3);
|
BOOST_TEST(type::instances == 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
#include <boost/type_traits/alignment_of.hpp>
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -30,7 +27,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(3);
|
boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(3);
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -38,7 +36,6 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[3]> a1 = boost::make_shared_noinit<int[3]>();
|
boost::shared_ptr<int[3]> a1 = boost::make_shared_noinit<int[3]>();
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -46,19 +43,16 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared_noinit<int[][2]>(2);
|
boost::shared_ptr<int[][2]> a1 = boost::make_shared_noinit<int[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[2][2]> a1 = boost::make_shared_noinit<int[2][2]>();
|
boost::shared_ptr<int[2][2]> a1 = boost::make_shared_noinit<int[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[]> a1 = boost::make_shared_noinit<const int[]>(3);
|
boost::shared_ptr<const int[]> a1 = boost::make_shared_noinit<const int[]>(3);
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -66,7 +60,6 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[3]> a1 = boost::make_shared_noinit<const int[3]>();
|
boost::shared_ptr<const int[3]> a1 = boost::make_shared_noinit<const int[3]>();
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -74,20 +67,16 @@ int main() {
|
|||||||
BOOST_TEST(a2 != 0);
|
BOOST_TEST(a2 != 0);
|
||||||
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> a1 = boost::make_shared_noinit<const int[][2]>(2);
|
boost::shared_ptr<const int[][2]> a1 = boost::make_shared_noinit<const int[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared_noinit<const int[2][2]>();
|
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared_noinit<const int[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
BOOST_TEST(a1.use_count() == 1);
|
BOOST_TEST(a1.use_count() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -99,8 +88,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[3]> a1 = boost::make_shared_noinit<type[3]>();
|
boost::shared_ptr<type[3]> a1 = boost::make_shared_noinit<type[3]>();
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -112,8 +99,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[][2]> a1 = boost::make_shared_noinit<type[][2]>(2);
|
boost::shared_ptr<type[][2]> a1 = boost::make_shared_noinit<type[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -122,8 +107,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<type[2][2]> a1 = boost::make_shared_noinit<type[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -132,8 +115,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[]> a1 = boost::make_shared_noinit<const type[]>(3);
|
boost::shared_ptr<const type[]> a1 = boost::make_shared_noinit<const type[]>(3);
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -144,8 +125,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[3]> a1 = boost::make_shared_noinit<const type[3]>();
|
boost::shared_ptr<const type[3]> a1 = boost::make_shared_noinit<const type[3]>();
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -156,8 +135,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<const type[][2]> a1 = boost::make_shared_noinit<const type[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -166,8 +143,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<const type[2][2]> a1 = boost::make_shared_noinit<const type[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -176,6 +151,5 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/smart_ptr/weak_ptr.hpp>
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
#include <boost/type_traits/alignment_of.hpp>
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -30,7 +27,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(3);
|
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(3);
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -41,7 +39,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[3]> a1 = boost::make_shared<int[3]>();
|
boost::shared_ptr<int[3]> a1 = boost::make_shared<int[3]>();
|
||||||
int* a2 = a1.get();
|
int* a2 = a1.get();
|
||||||
@@ -52,7 +49,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2);
|
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -62,7 +58,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>();
|
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -72,7 +67,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(3);
|
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(3);
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -83,7 +77,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[3]> a1 = boost::make_shared<const int[3]>();
|
boost::shared_ptr<const int[3]> a1 = boost::make_shared<const int[3]>();
|
||||||
const int* a2 = a1.get();
|
const int* a2 = a1.get();
|
||||||
@@ -94,7 +87,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1] == 0);
|
BOOST_TEST(a1[1] == 0);
|
||||||
BOOST_TEST(a1[2] == 0);
|
BOOST_TEST(a1[2] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(2);
|
boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -104,7 +96,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared<const int[2][2]>();
|
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared<const int[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -114,8 +105,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 0);
|
BOOST_TEST(a1[1][1] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -127,8 +116,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[3]> a1 = boost::make_shared<type[3]>();
|
boost::shared_ptr<type[3]> a1 = boost::make_shared<type[3]>();
|
||||||
type* a2 = a1.get();
|
type* a2 = a1.get();
|
||||||
@@ -140,8 +127,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[][2]> a1 = boost::make_shared<type[][2]>(2);
|
boost::shared_ptr<type[][2]> a1 = boost::make_shared<type[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -150,8 +135,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<type[2][2]> a1 = boost::make_shared<type[2][2]>();
|
boost::shared_ptr<type[2][2]> a1 = boost::make_shared<type[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -160,8 +143,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3);
|
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3);
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -172,8 +153,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const type[3]> a1 = boost::make_shared<const type[3]>();
|
boost::shared_ptr<const type[3]> a1 = boost::make_shared<const type[3]>();
|
||||||
const type* a2 = a1.get();
|
const type* a2 = a1.get();
|
||||||
@@ -184,8 +163,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<const type[][2]> a1 = boost::make_shared<const type[][2]>(2);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -194,8 +171,6 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
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::shared_ptr<const type[2][2]> a1 = boost::make_shared<const type[2][2]>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -204,6 +179,5 @@ int main() {
|
|||||||
a1.reset();
|
a1.reset();
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,29 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_shared_array.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
static unsigned int instances;
|
static unsigned int instances;
|
||||||
|
|
||||||
explicit type() {
|
explicit type() {
|
||||||
if (instances == 5) {
|
if (instances == 5) {
|
||||||
throw true;
|
throw true;
|
||||||
}
|
}
|
||||||
instances++;
|
instances++;
|
||||||
}
|
}
|
||||||
|
|
||||||
~type() {
|
~type() {
|
||||||
instances--;
|
instances--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type(const type&);
|
type(const type&);
|
||||||
type& operator=(const type&);
|
type& operator=(const type&);
|
||||||
@@ -31,70 +28,55 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
BOOST_TEST(type::instances == 0);
|
{
|
||||||
try {
|
try {
|
||||||
boost::make_shared<type[]>(6);
|
boost::make_shared<type[]>(6);
|
||||||
BOOST_ERROR("make_shared did not throw");
|
BOOST_ERROR("make_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::make_shared<type[][2]>(3);
|
boost::make_shared<type[][2]>(3);
|
||||||
BOOST_ERROR("make_shared did not throw");
|
BOOST_ERROR("make_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::make_shared<type[6]>();
|
boost::make_shared<type[6]>();
|
||||||
BOOST_ERROR("make_shared did not throw");
|
BOOST_ERROR("make_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::make_shared<type[3][2]>();
|
boost::make_shared<type[3][2]>();
|
||||||
BOOST_ERROR("make_shared did not throw");
|
BOOST_ERROR("make_shared did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::make_shared_noinit<type[]>(6);
|
boost::make_shared_noinit<type[]>(6);
|
||||||
BOOST_ERROR("make_shared_noinit did not throw");
|
BOOST_ERROR("make_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::make_shared_noinit<type[][2]>(3);
|
boost::make_shared_noinit<type[][2]>(3);
|
||||||
BOOST_ERROR("make_shared_noinit did not throw");
|
BOOST_ERROR("make_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::make_shared_noinit<type[6]>();
|
boost::make_shared_noinit<type[6]>();
|
||||||
BOOST_ERROR("make_shared_noinit did not throw");
|
BOOST_ERROR("make_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST(type::instances == 0);
|
|
||||||
try {
|
try {
|
||||||
boost::make_shared_noinit<type[3][2]>();
|
boost::make_shared_noinit<type[3][2]>();
|
||||||
BOOST_ERROR("make_shared_noinit did not throw");
|
BOOST_ERROR("make_shared_noinit did not throw");
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.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>
|
|
||||||
|
|
||||||
int main() {
|
Distributed under the Boost Software
|
||||||
|
License, Version 1.0.
|
||||||
|
http://boost.org/LICENSE_1_0.txt
|
||||||
|
*/
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(4, 1);
|
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(4, 1);
|
||||||
BOOST_TEST(a1[0] == 1);
|
BOOST_TEST(a1[0] == 1);
|
||||||
@@ -17,7 +18,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>(1);
|
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>(1);
|
||||||
BOOST_TEST(a1[0] == 1);
|
BOOST_TEST(a1[0] == 1);
|
||||||
@@ -25,7 +25,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(4, 1);
|
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(4, 1);
|
||||||
BOOST_TEST(a1[0] == 1);
|
BOOST_TEST(a1[0] == 1);
|
||||||
@@ -33,7 +32,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[4]> a1 = boost::make_shared<const int[4]>(1);
|
boost::shared_ptr<const int[4]> a1 = boost::make_shared<const int[4]>(1);
|
||||||
BOOST_TEST(a1[0] == 1);
|
BOOST_TEST(a1[0] == 1);
|
||||||
@@ -41,6 +39,5 @@ int main() {
|
|||||||
BOOST_TEST(a1[2] == 1);
|
BOOST_TEST(a1[2] == 1);
|
||||||
BOOST_TEST(a1[3] == 1);
|
BOOST_TEST(a1[3] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2012-2015 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.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>
|
|
||||||
|
|
||||||
int main() {
|
Distributed under the Boost Software
|
||||||
|
License, Version 1.0.
|
||||||
|
http://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)
|
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
|
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
|
||||||
@@ -18,7 +19,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ 0, 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][0] == 0);
|
||||||
@@ -26,7 +26,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(2, { 0, 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][0] == 0);
|
||||||
@@ -34,7 +33,6 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][0] == 0);
|
BOOST_TEST(a1[1][0] == 0);
|
||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared<const int[2][2]>({ 0, 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][0] == 0);
|
||||||
@@ -43,6 +41,5 @@ int main() {
|
|||||||
BOOST_TEST(a1[1][1] == 1);
|
BOOST_TEST(a1[1][1] == 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
}
|
@@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
@@ -41,7 +41,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
{
|
{
|
||||||
std::unique_ptr<type> a1 = boost::make_unique<type>();
|
std::unique_ptr<type> a1 = boost::make_unique<type>();
|
||||||
@@ -139,7 +140,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
@@ -30,7 +30,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
std::unique_ptr<int[]> a1 = boost::make_unique_noinit<int[]>(3);
|
std::unique_ptr<int[]> a1 = boost::make_unique_noinit<int[]>(3);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -81,7 +82,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
@@ -30,7 +30,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
std::unique_ptr<int[]> a1 = boost::make_unique<int[]>(3);
|
std::unique_ptr<int[]> a1 = boost::make_unique<int[]>(3);
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -105,7 +106,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_array.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
@@ -33,7 +33,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
try {
|
try {
|
||||||
boost::make_unique<type[]>(6);
|
boost::make_unique<type[]>(6);
|
||||||
@@ -70,7 +71,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
@@ -30,7 +30,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
std::unique_ptr<int> a1 = boost::make_unique_noinit<int>();
|
std::unique_ptr<int> a1 = boost::make_unique_noinit<int>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -58,7 +59,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
@@ -30,7 +30,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
std::unique_ptr<int> a1 = boost::make_unique<int>();
|
std::unique_ptr<int> a1 = boost::make_unique<int>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -65,7 +66,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
class type {
|
class type {
|
||||||
public:
|
public:
|
||||||
@@ -33,7 +33,8 @@ private:
|
|||||||
|
|
||||||
unsigned int type::instances = 0;
|
unsigned int type::instances = 0;
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
BOOST_TEST(type::instances == 0);
|
BOOST_TEST(type::instances == 0);
|
||||||
try {
|
try {
|
||||||
boost::make_unique<type>();
|
boost::make_unique<type>();
|
||||||
@@ -46,7 +47,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,22 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Glen Joseph Fernandes
|
(c) 2014 Glen Joseph Fernandes
|
||||||
* glenfe at live dot com
|
<glenjofe -at- gmail.com>
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License,
|
Distributed under the Boost Software
|
||||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
License, Version 1.0.
|
||||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
http://boost.org/LICENSE_1_0.txt
|
||||||
*/
|
*/
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
#include <boost/smart_ptr/make_unique.hpp>
|
||||||
|
|
||||||
struct type {
|
struct type {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
std::unique_ptr<type> a1 = boost::make_unique<type>();
|
std::unique_ptr<type> a1 = boost::make_unique<type>();
|
||||||
BOOST_TEST(a1.get() != 0);
|
BOOST_TEST(a1.get() != 0);
|
||||||
@@ -51,7 +52,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)));
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
{
|
boost::shared_ptr<base> boost_shared(new derived);
|
||||||
// Try casts with shared_ptr
|
base *plain = boost_shared.get();
|
||||||
|
|
||||||
boost::shared_ptr<base> ptr(new derived);
|
check_all_casts(boost_shared);
|
||||||
|
check_all_casts(plain);
|
||||||
#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() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return boost::report_errors();
|
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
|
170
test/shared_from_raw_test.cpp
Normal file
170
test/shared_from_raw_test.cpp
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
//
|
||||||
|
// shared_from_raw_test - based on shared_from_this_test
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002, 2003, 2014 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
class X
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void f() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
~X() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Y
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual boost::shared_ptr<X> getX() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
~Y() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
boost::shared_ptr<Y> createY();
|
||||||
|
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<Y> py = createY();
|
||||||
|
BOOST_TEST(py.get() != 0);
|
||||||
|
BOOST_TEST(py.use_count() == 1);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px = py->getX();
|
||||||
|
BOOST_TEST(px.get() != 0);
|
||||||
|
BOOST_TEST(py.use_count() == 2);
|
||||||
|
|
||||||
|
px->f();
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
|
boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px);
|
||||||
|
BOOST_TEST(py.get() == py2.get());
|
||||||
|
BOOST_TEST(!(py < py2 || py2 < py));
|
||||||
|
BOOST_TEST(py.use_count() == 3);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "py->getX() failed" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2();
|
||||||
|
void test3();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test();
|
||||||
|
test2();
|
||||||
|
test3();
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
// virtual inheritance to stress the implementation
|
||||||
|
// (prevents Y* -> impl*, enable_shared_from_raw* -> impl* casts)
|
||||||
|
|
||||||
|
class impl: public X, public virtual Y, public virtual boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void f()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual boost::shared_ptr<X> getX()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<impl> pi = boost::shared_from_raw( this );
|
||||||
|
BOOST_TEST( pi.get() == this );
|
||||||
|
return pi;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// intermediate impl2 to stress the implementation
|
||||||
|
|
||||||
|
class impl2: public impl
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
boost::shared_ptr<Y> createY()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<Y> pi(new impl2);
|
||||||
|
return pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<Y> pi(static_cast<impl2*>(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
struct V: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
void test3()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<V> p( new V );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr<V> q = boost::shared_from_raw( p.get() );
|
||||||
|
BOOST_TEST( p == q );
|
||||||
|
BOOST_TEST( !(p < q) && !(q < p) );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const & )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "shared_from_this( p.get() ) failed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
V v2( *p );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// shared_from_raw differs from shared_from_this;
|
||||||
|
// it will not throw here and will create a shared_ptr
|
||||||
|
|
||||||
|
boost::shared_ptr<V> r = boost::shared_from_raw( &v2 );
|
||||||
|
|
||||||
|
// check if the shared_ptr is correct and that it does
|
||||||
|
// not share ownership with p
|
||||||
|
|
||||||
|
BOOST_TEST( r.get() == &v2 );
|
||||||
|
BOOST_TEST( p != r );
|
||||||
|
BOOST_TEST( (p < r) || (r < p) );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const & )
|
||||||
|
{
|
||||||
|
BOOST_ERROR("shared_from_raw( &v2 ) failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
*p = V();
|
||||||
|
boost::shared_ptr<V> r = boost::shared_from_raw( p.get() );
|
||||||
|
BOOST_TEST( p == r );
|
||||||
|
BOOST_TEST( !(p < r) && !(r < p) );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const & )
|
||||||
|
{
|
||||||
|
BOOST_ERROR("shared_from_raw( p.get() ) threw bad_weak_ptr after *p = V()");
|
||||||
|
}
|
||||||
|
}
|
219
test/shared_from_raw_test2.cpp
Normal file
219
test/shared_from_raw_test2.cpp
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
//
|
||||||
|
// shared_from_raw_test2.cpp - based on esft_regtest.cpp
|
||||||
|
//
|
||||||
|
// Copyright (c) 2008, 2014 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
int destroyed_;
|
||||||
|
int deleted_;
|
||||||
|
int expected_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
X( X const& );
|
||||||
|
X& operator=( X const& );
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static int instances;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit X( int expected ): destroyed_( 0 ), deleted_( 0 ), expected_( expected )
|
||||||
|
{
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~X()
|
||||||
|
{
|
||||||
|
BOOST_TEST( deleted_ == expected_ );
|
||||||
|
BOOST_TEST( destroyed_ == 0 );
|
||||||
|
++destroyed_;
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef void (*deleter_type)( X* );
|
||||||
|
|
||||||
|
static void deleter( X * px )
|
||||||
|
{
|
||||||
|
++px->deleted_;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void deleter2( X * px )
|
||||||
|
{
|
||||||
|
++px->deleted_;
|
||||||
|
delete px;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int X::instances = 0;
|
||||||
|
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
X x( 0 );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
std::auto_ptr<X> px( new X( 0 ) );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px( new X( 0 ) );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
boost::weak_ptr<X> wp( px );
|
||||||
|
BOOST_TEST( !wp.expired() );
|
||||||
|
|
||||||
|
px.reset();
|
||||||
|
|
||||||
|
BOOST_TEST( wp.expired() );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
X x( 1 );
|
||||||
|
boost::shared_ptr<X> px( &x, X::deleter );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px );
|
||||||
|
BOOST_TEST( pd != 0 && *pd == X::deleter );
|
||||||
|
|
||||||
|
boost::weak_ptr<X> wp( px );
|
||||||
|
BOOST_TEST( !wp.expired() );
|
||||||
|
|
||||||
|
px.reset();
|
||||||
|
|
||||||
|
BOOST_TEST( wp.expired() );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px( new X( 1 ), X::deleter2 );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px );
|
||||||
|
BOOST_TEST( pd != 0 && *pd == X::deleter2 );
|
||||||
|
|
||||||
|
boost::weak_ptr<X> wp( px );
|
||||||
|
BOOST_TEST( !wp.expired() );
|
||||||
|
|
||||||
|
px.reset();
|
||||||
|
|
||||||
|
BOOST_TEST( wp.expired() );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
struct V: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
virtual ~V() {}
|
||||||
|
std::string m_;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct V2
|
||||||
|
{
|
||||||
|
virtual ~V2() {}
|
||||||
|
std::string m2_;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct W: V2, V
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
void test2()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<W> p( new W );
|
||||||
|
}
|
||||||
|
|
||||||
|
void test3()
|
||||||
|
{
|
||||||
|
V * p = new W;
|
||||||
|
boost::shared_ptr<void> pv( p );
|
||||||
|
BOOST_TEST( pv.get() == p );
|
||||||
|
BOOST_TEST( pv.use_count() == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
struct null_deleter
|
||||||
|
{
|
||||||
|
void operator()( void const* ) const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
void test4()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<V> pv( new V );
|
||||||
|
boost::shared_ptr<V> pv2( pv.get(), null_deleter() );
|
||||||
|
BOOST_TEST( pv2.get() == pv.get() );
|
||||||
|
BOOST_TEST( pv2.use_count() == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void test5()
|
||||||
|
{
|
||||||
|
V v;
|
||||||
|
|
||||||
|
boost::shared_ptr<V> p1( &v, null_deleter() );
|
||||||
|
BOOST_TEST( p1.get() == &v );
|
||||||
|
BOOST_TEST( p1.use_count() == 1 );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_from_raw( p1.get() );
|
||||||
|
}
|
||||||
|
catch( ... )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "shared_from_raw( p1.get() ) failed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
p1.reset();
|
||||||
|
|
||||||
|
boost::shared_ptr<V> p2( &v, null_deleter() );
|
||||||
|
BOOST_TEST( p2.get() == &v );
|
||||||
|
BOOST_TEST( p2.use_count() == 1 );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_from_raw( p2.get() );
|
||||||
|
}
|
||||||
|
catch( ... )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "shared_from_raw( p2.get() ) failed" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test();
|
||||||
|
test2();
|
||||||
|
test3();
|
||||||
|
test4();
|
||||||
|
test5();
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
52
test/shared_from_raw_test3.cpp
Normal file
52
test/shared_from_raw_test3.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// shared_from_raw_test3 - based on esft_second_ptr_test.cpp
|
||||||
|
//
|
||||||
|
// This test has been extracted from a real
|
||||||
|
// scenario that occurs in Boost.Python
|
||||||
|
//
|
||||||
|
// Copyright 2009, 2014 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
void null_deleter( void const* )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px( new X );
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px2( px.get(), null_deleter );
|
||||||
|
BOOST_TEST( px == px2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > qx = boost::shared_from_raw( px.get() );
|
||||||
|
|
||||||
|
BOOST_TEST( px == qx );
|
||||||
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "shared_from_raw( px.get() ) failed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
56
test/shared_from_raw_test4.cpp
Normal file
56
test/shared_from_raw_test4.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// shared_from_raw_test4 - based on esft_void_test.cpp
|
||||||
|
//
|
||||||
|
// Copyright 2009, 2014 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr< void const volatile > pv( new X );
|
||||||
|
boost::shared_ptr< void > pv2 = boost::const_pointer_cast< void >( pv );
|
||||||
|
boost::shared_ptr< X > px = boost::static_pointer_cast< X >( pv2 );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > qx = boost::shared_from_raw( px.get() );
|
||||||
|
|
||||||
|
BOOST_TEST( px == qx );
|
||||||
|
BOOST_TEST( !( px < qx ) && !( qx < px ) );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "shared_from_this( px.get() ) failed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr< X const volatile > px2( px );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X const volatile > qx2 = boost::shared_from_raw( px2.get() );
|
||||||
|
|
||||||
|
BOOST_TEST( px2 == qx2 );
|
||||||
|
BOOST_TEST( !( px2 < qx2 ) && !( qx2 < px2 ) );
|
||||||
|
}
|
||||||
|
catch( boost::bad_weak_ptr const& )
|
||||||
|
{
|
||||||
|
BOOST_ERROR( "shared_from_this( px2.get() ) failed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
@@ -1,9 +1,9 @@
|
|||||||
//
|
//
|
||||||
// esft_constructor_test.cpp
|
// shared_from_raw_test5.cpp - was esft_constructor_test.cpp
|
||||||
//
|
//
|
||||||
// A test for the new enable_shared_from_this support for calling
|
// A test for calling shared_from_raw from constructors
|
||||||
// shared_from_this from constructors (that is, prior to the
|
// (that is, prior to the object's ownership being passed to
|
||||||
// object's ownership being passed to an external shared_ptr).
|
// an external shared_ptr).
|
||||||
//
|
//
|
||||||
// Copyright (c) 2008 Frank Mori Hess
|
// Copyright (c) 2008 Frank Mori Hess
|
||||||
// Copyright (c) 2008 Peter Dimov
|
// Copyright (c) 2008 Peter Dimov
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <boost/smart_ptr/enable_shared_from_raw.hpp>
|
#include <boost/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/weak_ptr.hpp>
|
#include <boost/weak_ptr.hpp>
|
52
test/shared_from_raw_test6.cpp
Normal file
52
test/shared_from_raw_test6.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// shared_from_raw_test6
|
||||||
|
//
|
||||||
|
// Tests that dangling shared_ptr instances are caught by
|
||||||
|
// the BOOST_ASSERT in ~enable_shared_from_raw
|
||||||
|
//
|
||||||
|
// Copyright 2014 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
|
||||||
|
//
|
||||||
|
|
||||||
|
#define BOOST_ENABLE_ASSERT_HANDLER
|
||||||
|
#include <boost/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static int assertion_failed_ = 0;
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
void assertion_failed( char const * expr, char const * function, char const * file, long line )
|
||||||
|
{
|
||||||
|
printf( "Assertion '%s' failed in function '%s', file '%s', line %ld\n", expr, function, file, line );
|
||||||
|
++assertion_failed_;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px;
|
||||||
|
|
||||||
|
{
|
||||||
|
X x;
|
||||||
|
px = boost::shared_from_raw( &x );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( assertion_failed_, 1 );
|
||||||
|
|
||||||
|
// px is a dangling pointer here
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
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
|
239
test/sp_bml_unique_ptr_test.cpp
Normal file
239
test/sp_bml_unique_ptr_test.cpp
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
//
|
||||||
|
// sp_bml_unique_ptr_test.cpp
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012, 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/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <boost/move/unique_ptr.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
struct X: public boost::enable_shared_from_this< X >
|
||||||
|
{
|
||||||
|
static int instances;
|
||||||
|
|
||||||
|
X()
|
||||||
|
{
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~X()
|
||||||
|
{
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
X( X const & );
|
||||||
|
X & operator=( X const & );
|
||||||
|
};
|
||||||
|
|
||||||
|
int X::instances = 0;
|
||||||
|
|
||||||
|
struct Y
|
||||||
|
{
|
||||||
|
static int instances;
|
||||||
|
|
||||||
|
bool deleted_;
|
||||||
|
|
||||||
|
Y(): deleted_( false )
|
||||||
|
{
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~Y()
|
||||||
|
{
|
||||||
|
BOOST_TEST( deleted_ );
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Y( Y const & );
|
||||||
|
Y & operator=( Y const & );
|
||||||
|
};
|
||||||
|
|
||||||
|
int Y::instances = 0;
|
||||||
|
|
||||||
|
struct YD
|
||||||
|
{
|
||||||
|
void operator()( Y* p ) const
|
||||||
|
{
|
||||||
|
p->deleted_ = true;
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
boost::movelib::unique_ptr<X> p( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
boost::shared_ptr<X> p2( boost::move( p ) );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
BOOST_TEST( p.get() == 0 );
|
||||||
|
|
||||||
|
boost::shared_ptr<X> p3 = p2->shared_from_this();
|
||||||
|
BOOST_TEST( p2 == p3 );
|
||||||
|
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
p3.reset();
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<X>( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<X>( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
p3 = p2->shared_from_this();
|
||||||
|
BOOST_TEST( p2 == p3 );
|
||||||
|
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
p3.reset();
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
boost::movelib::unique_ptr<X> p( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
boost::shared_ptr<X const> p2( boost::move( p ) );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
BOOST_TEST( p.get() == 0 );
|
||||||
|
|
||||||
|
boost::shared_ptr<X const> p3 = p2->shared_from_this();
|
||||||
|
BOOST_TEST( p2 == p3 );
|
||||||
|
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
p3.reset();
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<X>( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<X>( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
p3 = p2->shared_from_this();
|
||||||
|
BOOST_TEST( p2 == p3 );
|
||||||
|
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
p3.reset();
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
boost::movelib::unique_ptr<X> p( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
boost::shared_ptr<void> p2( boost::move( p ) );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
BOOST_TEST( p.get() == 0 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<X>( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<X>( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
boost::movelib::unique_ptr<Y, YD> p( new Y, YD() );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
boost::shared_ptr<Y> p2( boost::move( p ) );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
BOOST_TEST( p.get() == 0 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<Y, YD>( new Y, YD() );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<Y, YD>( new Y, YD() );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
YD yd;
|
||||||
|
|
||||||
|
boost::movelib::unique_ptr<Y, YD&> p( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
boost::shared_ptr<Y> p2( boost::move( p ) );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
BOOST_TEST( p.get() == 0 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<Y, YD&>( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<Y, YD&>( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
YD yd;
|
||||||
|
|
||||||
|
boost::movelib::unique_ptr<Y, YD const&> p( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
boost::shared_ptr<Y> p2( boost::move( p ) );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
BOOST_TEST( p.get() == 0 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<Y, YD const&>( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2 = boost::movelib::unique_ptr<Y, YD const&>( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
23
test/sp_explicit_inst_test.cpp
Normal file
23
test/sp_explicit_inst_test.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// Explicit instantiations are reported to exist in user code
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 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>
|
||||||
|
|
||||||
|
template class boost::shared_ptr< int >;
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template class boost::shared_ptr< X >;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
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();
|
||||||
|
}
|
@@ -9,6 +9,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -37,7 +38,7 @@ private:
|
|||||||
|
|
||||||
int X::instances = 0;
|
int X::instances = 0;
|
||||||
|
|
||||||
void f( std::nullptr_t )
|
void f( boost::detail::sp_nullptr_t )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <boost/smart_ptr/enable_shared_from_raw.hpp>
|
#include <boost/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ void basic_weak_from_raw_test()
|
|||||||
{
|
{
|
||||||
X *p(new X);
|
X *p(new X);
|
||||||
boost::weak_ptr<X> weak = boost::weak_from_raw(p);
|
boost::weak_ptr<X> weak = boost::weak_from_raw(p);
|
||||||
BOOST_TEST(weak.expired());
|
BOOST_TEST(!weak.expired());
|
||||||
boost::shared_ptr<X> shared(p);
|
boost::shared_ptr<X> shared(p);
|
||||||
weak = boost::weak_from_raw(p);
|
weak = boost::weak_from_raw(p);
|
||||||
BOOST_TEST(weak.expired() == false);
|
BOOST_TEST(weak.expired() == false);
|
67
test/weak_from_raw_test2.cpp
Normal file
67
test/weak_from_raw_test2.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
//
|
||||||
|
// weak_from_raw_test2.cpp
|
||||||
|
//
|
||||||
|
// Test that weak_from_raw returns consistent values
|
||||||
|
// throughout the object lifetime
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
class X;
|
||||||
|
|
||||||
|
static boost::weak_ptr< X > r_;
|
||||||
|
|
||||||
|
void register_( boost::weak_ptr< X > const & r )
|
||||||
|
{
|
||||||
|
r_ = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void check_( boost::weak_ptr< X > const & r )
|
||||||
|
{
|
||||||
|
BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregister_( boost::weak_ptr< X > const & r )
|
||||||
|
{
|
||||||
|
BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
|
||||||
|
r_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
X()
|
||||||
|
{
|
||||||
|
register_( boost::shared_from_raw( this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
~X()
|
||||||
|
{
|
||||||
|
unregister_( boost::weak_from_raw( this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void check()
|
||||||
|
{
|
||||||
|
check_( boost::weak_from_raw( this ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px( new X );
|
||||||
|
px->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
46
test/weak_from_raw_test3.cpp
Normal file
46
test/weak_from_raw_test3.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// weak_from_raw_test3.cpp
|
||||||
|
//
|
||||||
|
// Test that weak_from_raw and shared_from_raw
|
||||||
|
// return consistent values from a constructor
|
||||||
|
//
|
||||||
|
// Copyright (c) 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
X()
|
||||||
|
{
|
||||||
|
boost::weak_ptr<X> p1 = boost::weak_from_raw( this );
|
||||||
|
BOOST_TEST( !p1.expired() );
|
||||||
|
|
||||||
|
boost::weak_ptr<X> p2 = boost::weak_from_raw( this );
|
||||||
|
BOOST_TEST( !p2.expired() );
|
||||||
|
BOOST_TEST( !( p1 < p2 ) && !( p2 < p1 ) );
|
||||||
|
|
||||||
|
boost::weak_ptr<X> p3 = boost::shared_from_raw( this );
|
||||||
|
BOOST_TEST( !( p1 < p3 ) && !( p3 < p1 ) );
|
||||||
|
|
||||||
|
boost::weak_ptr<X> p4 = boost::weak_from_raw( this );
|
||||||
|
BOOST_TEST( !p4.expired() );
|
||||||
|
BOOST_TEST( !( p3 < p4 ) && !( p4 < p3 ) );
|
||||||
|
BOOST_TEST( !( p1 < p4 ) && !( p4 < p1 ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px( new X );
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
67
test/weak_from_raw_test4.cpp
Normal file
67
test/weak_from_raw_test4.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
//
|
||||||
|
// weak_from_raw_test4.cpp
|
||||||
|
//
|
||||||
|
// As weak_from_raw_test2.cpp, but uses weak_from_raw
|
||||||
|
// in the constructor
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014, 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
class X;
|
||||||
|
|
||||||
|
static boost::weak_ptr< X > r_;
|
||||||
|
|
||||||
|
void register_( boost::weak_ptr< X > const & r )
|
||||||
|
{
|
||||||
|
r_ = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void check_( boost::weak_ptr< X > const & r )
|
||||||
|
{
|
||||||
|
BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregister_( boost::weak_ptr< X > const & r )
|
||||||
|
{
|
||||||
|
BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
|
||||||
|
r_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
X()
|
||||||
|
{
|
||||||
|
register_( boost::weak_from_raw( this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
~X()
|
||||||
|
{
|
||||||
|
unregister_( boost::weak_from_raw( this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void check()
|
||||||
|
{
|
||||||
|
check_( boost::weak_from_raw( this ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px( new X );
|
||||||
|
px->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
45
test/weak_from_raw_test5.cpp
Normal file
45
test/weak_from_raw_test5.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
//
|
||||||
|
// weak_from_raw_test5.cpp
|
||||||
|
//
|
||||||
|
// Tests whether pointers returned from weak_from_raw
|
||||||
|
// expire properly
|
||||||
|
//
|
||||||
|
// Copyright 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/smart_ptr/enable_shared_from_raw.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_raw
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit X( boost::weak_ptr< X > & r )
|
||||||
|
{
|
||||||
|
r = boost::weak_from_raw( this );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::weak_ptr<X> p1, p2;
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px( new X( p1 ) );
|
||||||
|
p2 = boost::weak_from_raw( px.get() );
|
||||||
|
|
||||||
|
BOOST_TEST( !p1.expired() );
|
||||||
|
BOOST_TEST( !p2.expired() );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_TEST( p1.expired() );
|
||||||
|
BOOST_TEST( p2.expired() );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
52
test/weak_from_this_test.cpp
Normal file
52
test/weak_from_this_test.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
//
|
||||||
|
// weak_from_this_test.cpp
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002, 2003, 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/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
class V: public boost::enable_shared_from_this<V>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
void test()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<V> p( new V );
|
||||||
|
|
||||||
|
boost::weak_ptr<V> q = p;
|
||||||
|
BOOST_TEST( !q.expired() );
|
||||||
|
|
||||||
|
boost::weak_ptr<V> q2 = p->weak_from_this();
|
||||||
|
BOOST_TEST( !q2.expired() );
|
||||||
|
BOOST_TEST( !(q < q2) && !(q2 < q) );
|
||||||
|
|
||||||
|
V v2( *p );
|
||||||
|
|
||||||
|
boost::weak_ptr<V> q3 = v2.weak_from_this();
|
||||||
|
BOOST_TEST( q3.expired() );
|
||||||
|
|
||||||
|
*p = V();
|
||||||
|
|
||||||
|
boost::weak_ptr<V> q4 = p->shared_from_this();
|
||||||
|
BOOST_TEST( !q4.expired() );
|
||||||
|
BOOST_TEST( !(q < q4) && !(q4 < q) );
|
||||||
|
BOOST_TEST( !(q2 < q4) && !(q4 < q2) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test();
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
60
test/weak_from_this_test2.cpp
Normal file
60
test/weak_from_this_test2.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
//
|
||||||
|
// weak_from_this_test2.cpp
|
||||||
|
//
|
||||||
|
// Tests weak_from_this in a destructor
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014, 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/smart_ptr/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
class X: public boost::enable_shared_from_this< X >
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
boost::weak_ptr<X> px_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
X()
|
||||||
|
{
|
||||||
|
boost::weak_ptr<X> p1 = weak_from_this();
|
||||||
|
BOOST_TEST( p1._empty() );
|
||||||
|
BOOST_TEST( p1.expired() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void check()
|
||||||
|
{
|
||||||
|
boost::weak_ptr<X> p2 = weak_from_this();
|
||||||
|
BOOST_TEST( !p2.expired() );
|
||||||
|
|
||||||
|
BOOST_TEST( p2.lock().get() == this );
|
||||||
|
|
||||||
|
px_ = p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
~X()
|
||||||
|
{
|
||||||
|
boost::weak_ptr<X> p3 = weak_from_this();
|
||||||
|
BOOST_TEST( p3.expired() );
|
||||||
|
|
||||||
|
BOOST_TEST( !(px_ < p3) && !(p3 < px_) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::shared_ptr< X > px( new X );
|
||||||
|
px->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user