Update unit tests for make_unique

This commit is contained in:
Glen Fernandes
2017-03-06 08:36:57 -05:00
parent 324347b9ec
commit 650537da60
10 changed files with 270 additions and 290 deletions

View File

@ -1,10 +1,9 @@
/*
(c) 2014-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2012-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
#define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
@ -15,6 +14,7 @@ http://boost.org/LICENSE_1_0.txt
namespace boost {
namespace detail {
template<class T>
struct up_if_object {
typedef std::unique_ptr<T> type;
@ -56,10 +56,12 @@ template<class T>
struct up_element<T[]> {
typedef T type;
};
} /* detail */
template<class T>
inline typename detail::up_if_object<T>::type make_unique()
inline typename detail::up_if_object<T>::type
make_unique()
{
return std::unique_ptr<T>(new T());
}
@ -67,7 +69,7 @@ inline typename detail::up_if_object<T>::type make_unique()
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<class T, class... Args>
inline typename detail::up_if_object<T>::type
make_unique(Args&&... args)
make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
@ -75,31 +77,34 @@ inline typename detail::up_if_object<T>::type
template<class T>
inline typename detail::up_if_object<T>::type
make_unique(typename detail::up_remove_reference<T>::type&& value)
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()
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)
inline typename detail::up_if_array<T>::type
make_unique(std::size_t size)
{
return std::unique_ptr<T>(new
typename detail::up_element<T>::type[n]());
return std::unique_ptr<T>(new typename
detail::up_element<T>::type[size]());
}
template<class T>
inline typename detail::up_if_array<T>::type
make_unique_noinit(std::size_t n)
make_unique_noinit(std::size_t size)
{
return std::unique_ptr<T>(new
typename detail::up_element<T>::type[n]);
return std::unique_ptr<T>(new typename
detail::up_element<T>::type[size]);
}
} /* boost */
#endif

View File

@ -21,10 +21,8 @@
template&lt;class U&gt; // U is not array
unique_ptr&lt;U&gt; <a href="#functions">make_unique</a>();
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template&lt;class U, class... Args&gt; // U is not array
unique_ptr&lt;U&gt; <a href="#functions">make_unique</a>(Args&amp;&amp;... args);
#endif
template&lt;class U&gt; // U is not array
unique_ptr&lt;U&gt; <a href="#functions">make_unique</a>(U&amp;&amp; value);
@ -40,9 +38,9 @@
}</pre>
<h2><a name="common">Common Requirements</a></h2>
<pre>template&lt;class U&gt;
unique_ptr&lt;U&gt; make_unique(<em>args</em>);
template&lt;class U&gt;
unique_ptr&lt;U&gt; make_unique_noinit(<em>args</em>);</pre>
unique_ptr&lt;U&gt; make_unique(<em>args</em>);</pre>
<pre>template&lt;class U&gt;
unique_ptr&lt;U&gt; make_unique_noinit(<em>args</em>);</pre>
<blockquote>
<p><b>Effects:</b> Allocates memory for an object of type <code>U</code>
(or <code>T[size]</code> when <code>U</code> is <code>T[]</code>,
@ -82,8 +80,8 @@ unique_ptr&lt;U&gt; make_unique(Args&amp;&amp;... args);</pre>
resolution when <code>U</code> is not an array type.</p>
<p><b>Examples:</b></p>
<blockquote>
<pre>unique_ptr&lt;float&gt; p1 = boost::make_unique&lt;float&gt;();
unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;(x, y);</pre>
<pre>unique_ptr&lt;float&gt; p1 = boost::make_unique&lt;float&gt;();</pre>
<pre>unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;(x, y);</pre>
</blockquote>
</blockquote>
<pre>template&lt;class U&gt;
@ -95,8 +93,8 @@ unique_ptr&lt;U&gt; make_unique(U&amp;&amp; value);</pre>
resolution when <code>U</code> is not an array type.</p>
<p><b>Examples:</b></p>
<blockquote>
<pre>unique_ptr&lt;string&gt; p1 = boost::make_unique&lt;string&gt;({'a', 'b'});
unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;({-10, 25});</pre>
<pre>unique_ptr&lt;string&gt; p1 = boost::make_unique&lt;string&gt;({'a', 'b'});</pre>
<pre>unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;({-10, 25});</pre>
</blockquote>
</blockquote>
<pre>template&lt;class U&gt;
@ -108,8 +106,8 @@ unique_ptr&lt;U&gt; make_unique(size_t size);</pre>
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
<p><b>Examples:</b></p>
<blockquote>
<pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique&lt;double[]&gt;(4);
unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique&lt;int[][2]&gt;(2);</pre>
<pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique&lt;double[]&gt;(4);</pre>
<pre>unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique&lt;int[][2]&gt;(2);</pre>
</blockquote>
</blockquote>
<pre>template&lt;class U&gt;
@ -121,8 +119,8 @@ unique_ptr&lt;U&gt; make_unique_noinit();</pre>
resolution when <code>U</code> is not an array type.</p>
<p><b>Examples:</b></p>
<blockquote>
<pre>unique_ptr&lt;float&gt; p1 = boost::make_unique_noinit&lt;float&gt;();
unique_ptr&lt;point&gt; p2 = boost::make_unique_noinit&lt;point&gt;();</pre>
<pre>unique_ptr&lt;float&gt; p1 = boost::make_unique_noinit&lt;float&gt;();</pre>
<pre>unique_ptr&lt;point&gt; p2 = boost::make_unique_noinit&lt;point&gt;();</pre>
</blockquote>
</blockquote>
<pre>template&lt;class U&gt;
@ -134,8 +132,8 @@ unique_ptr&lt;U&gt; make_unique_noinit(size_t size);</pre>
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
<p><b>Examples:</b></p>
<blockquote>
<pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique_noinit&lt;double[]&gt;(4);
unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique_noinit&lt;int[][2]&gt;(2);</pre>
<pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique_noinit&lt;double[]&gt;(4);</pre>
<pre>unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique_noinit&lt;int[][2]&gt;(2);</pre>
</blockquote>
</blockquote>
<h2><a name="history">History</a></h2>

View File

@ -1,148 +1,155 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
#include <boost/detail/lightweight_test.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/smart_ptr/make_unique.hpp>
class type {
public:
static unsigned int instances;
static unsigned instances;
explicit type(int v1 = 0,
int v2 = 0,
int v3 = 0,
int v4 = 0,
int v5 = 0,
int v6 = 0,
int v7 = 0,
int v8 = 0,
int v9 = 0)
: sum(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) {
instances++;
type(int v1 = 0,
int v2 = 0,
int v3 = 0,
int v4 = 0,
int v5 = 0,
int v6 = 0,
int v7 = 0,
int v8 = 0,
int v9 = 0)
: sum_(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) {
++instances;
}
~type() {
instances--;
--instances;
}
const int sum;
int sum() const {
return sum_;
}
private:
int sum_;
type(const type&);
type& operator=(const type&);
};
unsigned int type::instances = 0;
unsigned type::instances = 0;
int main()
{
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type> a1 = boost::make_unique<type>();
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result = boost::make_unique<type>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 0);
a1.reset();
BOOST_TEST(result->sum() == 0);
result.reset();
BOOST_TEST(type::instances == 0);
}
#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES )
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result = boost::make_unique<type>(1);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1);
a1.reset();
BOOST_TEST(result->sum() == 1);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result = boost::make_unique<type>(1, 2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>(1, 2, 3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2 + 3);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2 + 3);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>(1, 2, 3, 4);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>(1, 2, 3, 4, 5);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>(1, 2, 3, 4, 5, 6);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
result.reset();
BOOST_TEST(type::instances == 0);
}
{
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
a1.reset();
BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
result.reset();
BOOST_TEST(type::instances == 0);
}
#endif
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@ -1,10 +1,9 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt
class type {
public:
static unsigned int instances;
static unsigned instances;
explicit type() {
instances++;
type() {
++instances;
}
~type() {
instances--;
--instances;
}
private:
@ -28,63 +27,61 @@ private:
type& operator=(const type&);
};
unsigned int type::instances = 0;
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int[]> a1 = boost::make_unique_noinit<int[]>(3);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<int[]> result =
boost::make_unique_noinit<int[]>(3);
BOOST_TEST(result.get() != 0);
}
{
std::unique_ptr<int[][2]> a1 = boost::make_unique_noinit<int[][2]>(2);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<int[][2]> result =
boost::make_unique_noinit<int[][2]>(2);
BOOST_TEST(result.get() != 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type[]> a1 = boost::make_unique_noinit<type[]>(3);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type[]> result =
boost::make_unique_noinit<type[]>(3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type[][2]> a1 = boost::make_unique_noinit<type[][2]>(2);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type[][2]> result =
boost::make_unique_noinit<type[][2]>(2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type[]> a1 = boost::make_unique_noinit<const type[]>(3);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<const type[]> result =
boost::make_unique_noinit<const type[]>(3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type[][2]> a1 = boost::make_unique_noinit<const type[][2]>(2);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<const type[][2]> result =
boost::make_unique_noinit<const type[][2]>(2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@ -1,10 +1,9 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt
class type {
public:
static unsigned int instances;
static unsigned instances;
explicit type() {
instances++;
type() {
++instances;
}
~type() {
instances--;
--instances;
}
private:
@ -28,87 +27,84 @@ private:
type& operator=(const type&);
};
unsigned int type::instances = 0;
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int[]> a1 = boost::make_unique<int[]>(3);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
std::unique_ptr<int[]> result = boost::make_unique<int[]>(3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
std::unique_ptr<int[][2]> a1 = boost::make_unique<int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
std::unique_ptr<int[][2]> result =
boost::make_unique<int[][2]>(2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
{
std::unique_ptr<const int[]> a1 = boost::make_unique<const int[]>(3);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
std::unique_ptr<const int[]> result =
boost::make_unique<const int[]>(3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0] == 0);
BOOST_TEST(result[1] == 0);
BOOST_TEST(result[2] == 0);
}
{
std::unique_ptr<const int[][2]> a1 = boost::make_unique<const int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
std::unique_ptr<const int[][2]> result =
boost::make_unique<const int[][2]>(2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(result[0][0] == 0);
BOOST_TEST(result[0][1] == 0);
BOOST_TEST(result[1][0] == 0);
BOOST_TEST(result[1][1] == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type[]> a1 = boost::make_unique<type[]>(3);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type[]> result =
boost::make_unique<type[]>(3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type[][2]> a1 = boost::make_unique<type[][2]>(2);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type[][2]> result =
boost::make_unique<type[][2]>(2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type[]> a1 = boost::make_unique<const type[]>(3);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<const type[]> result =
boost::make_unique<const type[]>(3);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 3);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type[][2]> a1 = boost::make_unique<const type[][2]>(2);
BOOST_TEST(a1.get() != 0);
std::unique_ptr<const type[][2]> result =
boost::make_unique<const type[][2]>(2);
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 4);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@ -1,10 +1,9 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
@ -13,17 +12,17 @@ http://boost.org/LICENSE_1_0.txt
class type {
public:
static unsigned int instances;
static unsigned instances;
explicit type() {
type() {
if (instances == 5) {
throw true;
}
instances++;
++instances;
}
~type() {
instances--;
--instances;
}
private:
@ -31,7 +30,7 @@ private:
type& operator=(const type&);
};
unsigned int type::instances = 0;
unsigned type::instances = 0;
int main()
{
@ -42,7 +41,6 @@ int main()
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_unique<type[][2]>(3);
@ -50,7 +48,6 @@ int main()
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_unique_noinit<type[]>(6);
@ -58,7 +55,6 @@ int main()
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_unique_noinit<type[][2]>(3);
@ -66,14 +62,11 @@ int main()
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@ -1,10 +1,9 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt
class type {
public:
static unsigned int instances;
static unsigned instances;
explicit type() {
instances++;
type() {
++instances;
}
~type() {
instances--;
--instances;
}
private:
@ -28,40 +27,37 @@ private:
type& operator=(const type&);
};
unsigned int type::instances = 0;
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int> a1 = boost::make_unique_noinit<int>();
BOOST_TEST(a1.get() != 0);
std::unique_ptr<int> result = boost::make_unique_noinit<int>();
BOOST_TEST(result.get() != 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type> a1 = boost::make_unique_noinit<type>();
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique_noinit<type>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type> a1 = boost::make_unique_noinit<const type>();
BOOST_TEST(a1.get() != 0);
std::unique_ptr<const type> result =
boost::make_unique_noinit<const type>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@ -1,10 +1,9 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt
class type {
public:
static unsigned int instances;
static unsigned instances;
explicit type() {
instances++;
type() {
++instances;
}
~type() {
instances--;
--instances;
}
private:
@ -28,47 +27,44 @@ private:
type& operator=(const type&);
};
unsigned int type::instances = 0;
unsigned type::instances = 0;
int main()
{
{
std::unique_ptr<int> a1 = boost::make_unique<int>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(*a1 == 0);
std::unique_ptr<int> result = boost::make_unique<int>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(*result == 0);
}
{
std::unique_ptr<const int> a1 = boost::make_unique<const int>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(*a1 == 0);
std::unique_ptr<const int> result =
boost::make_unique<const int>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(*result == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<type> a1 = boost::make_unique<type>();
BOOST_TEST(a1.get() != 0);
std::unique_ptr<type> result =
boost::make_unique<type>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
std::unique_ptr<const type> a1 = boost::make_unique<const type>();
BOOST_TEST(a1.get() != 0);
std::unique_ptr<const type> result =
boost::make_unique<const type>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(type::instances == 1);
a1.reset();
result.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@ -1,10 +1,9 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
@ -13,17 +12,17 @@ http://boost.org/LICENSE_1_0.txt
class type {
public:
static unsigned int instances;
static unsigned instances;
explicit type() {
type() {
if (instances == 0) {
throw true;
}
instances++;
++instances;
}
~type() {
instances--;
--instances;
}
private:
@ -31,7 +30,7 @@ private:
type& operator=(const type&);
};
unsigned int type::instances = 0;
unsigned type::instances = 0;
int main()
{
@ -42,14 +41,11 @@ int main()
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@ -1,10 +1,9 @@
/*
(c) 2014 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Copyright 2014 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_SMART_PTR)
@ -19,42 +18,39 @@ struct type {
int main()
{
{
std::unique_ptr<type> a1 = boost::make_unique<type>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1->x == 0);
BOOST_TEST(a1->y == 0);
std::unique_ptr<type> result = boost::make_unique<type>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->x == 0);
BOOST_TEST(result->y == 0);
}
{
std::unique_ptr<const type> a1 = boost::make_unique<const type>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1->x == 0);
BOOST_TEST(a1->y == 0);
std::unique_ptr<const type> result =
boost::make_unique<const type>();
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->x == 0);
BOOST_TEST(result->y == 0);
}
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{
std::unique_ptr<type> a1 = boost::make_unique<type>({ 1, 2 });
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1->x == 1);
BOOST_TEST(a1->y == 2);
std::unique_ptr<type> result =
boost::make_unique<type>({ 1, 2 });
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->x == 1);
BOOST_TEST(result->y == 2);
}
{
std::unique_ptr<const type> a1 = boost::make_unique<const type>({ 1, 2 });
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1->x == 1);
BOOST_TEST(a1->y == 2);
std::unique_ptr<const type> result =
boost::make_unique<const type>({ 1, 2 });
BOOST_TEST(result.get() != 0);
BOOST_TEST(result->x == 1);
BOOST_TEST(result->y == 2);
}
#endif
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif