mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-16 01:15:27 +02:00
Add fourth form of make_unique for objects
To support initialization syntax that Args&&... cannot forward perfectly.
This commit is contained in:
51
test/make_unique_value_test.cpp
Normal file
51
test/make_unique_value_test.cpp
Normal file
@@ -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