forked from boostorg/smart_ptr
Update unit tests for make_unique
This commit is contained in:
1 parent
324347b9ec
commit
650537da60
10 files changed
+270
-290
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
+24
-28
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user