forked from boostorg/smart_ptr
Add fourth form of make_unique for objects
To support initialization syntax that Args&&... cannot forward perfectly.
This commit is contained in:
@@ -151,6 +151,7 @@ import testing ;
|
||||
|
||||
[ run make_unique_test.cpp ]
|
||||
[ run make_unique_args_test.cpp ]
|
||||
[ run make_unique_value_test.cpp ]
|
||||
[ run make_unique_noinit_test.cpp ]
|
||||
[ run make_unique_throws_test.cpp ]
|
||||
[ run make_unique_array_test.cpp ]
|
||||
|
||||
@@ -53,7 +53,7 @@ int main() {
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES )
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1);
|
||||
@@ -62,7 +62,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2);
|
||||
@@ -71,7 +71,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2, 3);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3);
|
||||
@@ -80,7 +80,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2, 3, 4);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4);
|
||||
@@ -89,7 +89,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5);
|
||||
@@ -98,7 +98,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6);
|
||||
@@ -107,7 +107,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7);
|
||||
@@ -116,7 +116,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
|
||||
@@ -125,7 +125,7 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
|
||||
|
||||
@@ -40,17 +40,7 @@ int main() {
|
||||
std::unique_ptr<int[][2]> a1 = boost::make_unique_noinit<int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const int[]> a1 = boost::make_unique_noinit<const int[]>(3);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const int[][2]> a1 = boost::make_unique_noinit<const int[][2]>(2);
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
}
|
||||
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type[]> a1 = boost::make_unique_noinit<type[]>(3);
|
||||
@@ -72,7 +62,6 @@ int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type[]> a1 = boost::make_unique_noinit<const type[]>(3);
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 3);
|
||||
a1.reset();
|
||||
|
||||
@@ -35,11 +35,6 @@ int main() {
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<const int> a1 = boost::make_unique_noinit<const int>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
}
|
||||
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<type> a1 = boost::make_unique_noinit<type>();
|
||||
@@ -52,7 +47,6 @@ int main() {
|
||||
BOOST_TEST(type::instances == 0);
|
||||
{
|
||||
std::unique_ptr<const type> a1 = boost::make_unique_noinit<const type>();
|
||||
const type* a2 = a1.get();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(type::instances == 1);
|
||||
a1.reset();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/smart_ptr/make_unique_object.hpp>
|
||||
|
||||
struct type {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
int main() {
|
||||
#if !defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
{
|
||||
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<const type> a1 = boost::make_unique<const type>();
|
||||
BOOST_TEST(a1.get() != 0);
|
||||
BOOST_TEST(a1->x == 0);
|
||||
BOOST_TEST(a1->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<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);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user