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 Copyright 2012-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com> (glenjofe@gmail.com)
Distributed under the Boost Software Distributed under the Boost Software License, Version 1.0.
License, Version 1.0. (http://www.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
@ -15,6 +14,7 @@ http://boost.org/LICENSE_1_0.txt
namespace boost { namespace boost {
namespace detail { namespace detail {
template<class T> template<class T>
struct up_if_object { struct up_if_object {
typedef std::unique_ptr<T> type; typedef std::unique_ptr<T> type;
@ -56,10 +56,12 @@ template<class T>
struct up_element<T[]> { struct up_element<T[]> {
typedef T type; typedef T type;
}; };
} /* detail */ } /* detail */
template<class T> 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()); return std::unique_ptr<T>(new T());
} }
@ -81,25 +83,28 @@ inline typename detail::up_if_object<T>::type
} }
template<class T> 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); return std::unique_ptr<T>(new T);
} }
template<class 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 return std::unique_ptr<T>(new typename
typename detail::up_element<T>::type[n]()); detail::up_element<T>::type[size]());
} }
template<class T> template<class T>
inline typename detail::up_if_array<T>::type 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 return std::unique_ptr<T>(new typename
typename detail::up_element<T>::type[n]); detail::up_element<T>::type[size]);
} }
} /* boost */ } /* boost */
#endif #endif

View File

@ -21,10 +21,8 @@
template&lt;class U&gt; // U is not array template&lt;class U&gt; // U is not array
unique_ptr&lt;U&gt; <a href="#functions">make_unique</a>(); 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 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); 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 template&lt;class U&gt; // U is not array
unique_ptr&lt;U&gt; <a href="#functions">make_unique</a>(U&amp;&amp; value); unique_ptr&lt;U&gt; <a href="#functions">make_unique</a>(U&amp;&amp; value);
@ -40,8 +38,8 @@
}</pre> }</pre>
<h2><a name="common">Common Requirements</a></h2> <h2><a name="common">Common Requirements</a></h2>
<pre>template&lt;class U&gt; <pre>template&lt;class U&gt;
unique_ptr&lt;U&gt; make_unique(<em>args</em>); unique_ptr&lt;U&gt; make_unique(<em>args</em>);</pre>
template&lt;class U&gt; <pre>template&lt;class U&gt;
unique_ptr&lt;U&gt; make_unique_noinit(<em>args</em>);</pre> unique_ptr&lt;U&gt; make_unique_noinit(<em>args</em>);</pre>
<blockquote> <blockquote>
<p><b>Effects:</b> Allocates memory for an object of type <code>U</code> <p><b>Effects:</b> Allocates memory for an object of type <code>U</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> resolution when <code>U</code> is not an array type.</p>
<p><b>Examples:</b></p> <p><b>Examples:</b></p>
<blockquote> <blockquote>
<pre>unique_ptr&lt;float&gt; p1 = boost::make_unique&lt;float&gt;(); <pre>unique_ptr&lt;float&gt; p1 = boost::make_unique&lt;float&gt;();</pre>
unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;(x, y);</pre> <pre>unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;(x, y);</pre>
</blockquote> </blockquote>
</blockquote> </blockquote>
<pre>template&lt;class U&gt; <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> resolution when <code>U</code> is not an array type.</p>
<p><b>Examples:</b></p> <p><b>Examples:</b></p>
<blockquote> <blockquote>
<pre>unique_ptr&lt;string&gt; p1 = boost::make_unique&lt;string&gt;({'a', 'b'}); <pre>unique_ptr&lt;string&gt; p1 = boost::make_unique&lt;string&gt;({'a', 'b'});</pre>
unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;({-10, 25});</pre> <pre>unique_ptr&lt;point&gt; p2 = boost::make_unique&lt;point&gt;({-10, 25});</pre>
</blockquote> </blockquote>
</blockquote> </blockquote>
<pre>template&lt;class U&gt; <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> resolution when <code>U</code> is of the form <code>T[]</code>.</p>
<p><b>Examples:</b></p> <p><b>Examples:</b></p>
<blockquote> <blockquote>
<pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique&lt;double[]&gt;(4); <pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique&lt;double[]&gt;(4);</pre>
unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique&lt;int[][2]&gt;(2);</pre> <pre>unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique&lt;int[][2]&gt;(2);</pre>
</blockquote> </blockquote>
</blockquote> </blockquote>
<pre>template&lt;class U&gt; <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> resolution when <code>U</code> is not an array type.</p>
<p><b>Examples:</b></p> <p><b>Examples:</b></p>
<blockquote> <blockquote>
<pre>unique_ptr&lt;float&gt; p1 = boost::make_unique_noinit&lt;float&gt;(); <pre>unique_ptr&lt;float&gt; p1 = boost::make_unique_noinit&lt;float&gt;();</pre>
unique_ptr&lt;point&gt; p2 = boost::make_unique_noinit&lt;point&gt;();</pre> <pre>unique_ptr&lt;point&gt; p2 = boost::make_unique_noinit&lt;point&gt;();</pre>
</blockquote> </blockquote>
</blockquote> </blockquote>
<pre>template&lt;class U&gt; <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> resolution when <code>U</code> is of the form <code>T[]</code>.</p>
<p><b>Examples:</b></p> <p><b>Examples:</b></p>
<blockquote> <blockquote>
<pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique_noinit&lt;double[]&gt;(4); <pre>unique_ptr&lt;double[]&gt; p1 = boost::make_unique_noinit&lt;double[]&gt;(4);</pre>
unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique_noinit&lt;int[][2]&gt;(2);</pre> <pre>unique_ptr&lt;int[][2]&gt; p2 = boost::make_unique_noinit&lt;int[][2]&gt;(2);</pre>
</blockquote> </blockquote>
</blockquote> </blockquote>
<h2><a name="history">History</a></h2> <h2><a name="history">History</a></h2>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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