1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Howard Hinnant 2009
4 // (C) Copyright Ion Gaztanaga 2014-2014.
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/move for documentation.
12 //////////////////////////////////////////////////////////////////////////////
13 #include <boost/move/utility_core.hpp>
14 #include <boost/move/unique_ptr.hpp>
15 #include <boost/move/detail/type_traits.hpp>
16 #include <boost/static_assert.hpp>
17 #include <boost/core/lightweight_test.hpp>
19 //////////////////////////////////////////////
21 // The initial implementation of these tests
22 // was written by Howard Hinnant.
24 // These test were later refactored grouping
25 // and porting them to Boost.Move.
27 // Many thanks to Howard for releasing his C++03
28 // unique_ptr implementation with such detailed
31 //////////////////////////////////////////////
33 #include "unique_ptr_test_utils_beg.hpp"
35 namespace bml
= ::boost::movelib
;
36 namespace bmupmu
= ::boost::move_upmu
;
38 ////////////////////////////////
39 // unique_ptr_pointer_type
40 ////////////////////////////////
41 namespace unique_ptr_pointer_type
{
48 // Test unique_ptr::pointer type
53 typedef bml::unique_ptr
<int> P
;
54 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, int*>::value
));
57 typedef bml::unique_ptr
<int, Deleter
> P
;
58 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, Deleter::pointer
>::value
));
60 //Unbounded array unique_ptr
62 typedef bml::unique_ptr
<int[]> P
;
63 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, int*>::value
));
66 typedef bml::unique_ptr
<int[], Deleter
> P
;
67 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, Deleter::pointer
>::value
));
69 //Bounded array unique_ptr
71 typedef bml::unique_ptr
<int[5]> P
;
72 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, int*>::value
));
75 typedef bml::unique_ptr
<int[5], Deleter
> P
;
76 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, Deleter::pointer
>::value
));
78 //Unbounded array of bounded array unique_ptr
80 typedef int int_5_t
[5];
81 typedef bml::unique_ptr
<int_5_t
[]> P
;
82 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, int_5_t
*>::value
));
85 typedef int int_5_t
[5];
86 typedef bml::unique_ptr
<int_5_t
[], Deleter
> P
;
87 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::pointer
, Deleter::pointer
>::value
));
91 } //namespace unique_ptr_pointer_type {
93 ////////////////////////////////
94 // unique_ptr_deleter_type
95 ////////////////////////////////
96 namespace unique_ptr_deleter_type
{
101 // Test unique_ptr::deleter type
106 typedef bml::unique_ptr
<int> P
;
107 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::deleter_type
, bml::default_delete
<int> >::value
));
110 typedef bml::unique_ptr
<int, Deleter
> P
;
111 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::deleter_type
, Deleter
>::value
));
113 //Unbounded array unique_ptr
115 typedef bml::unique_ptr
<int[]> P
;
116 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::deleter_type
, bml::default_delete
<int[]> >::value
));
119 typedef bml::unique_ptr
<int[], Deleter
> P
;
120 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::deleter_type
, Deleter
>::value
));
122 //Bounded array unique_ptr
124 typedef bml::unique_ptr
<int[2]> P
;
125 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::deleter_type
, bml::default_delete
<int[2]> >::value
));
128 typedef bml::unique_ptr
<int[2], Deleter
> P
;
129 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::deleter_type
, Deleter
>::value
));
133 } //namespace unique_ptr_deleter_type {
135 ////////////////////////////////
136 // unique_ptr_element_type
137 ////////////////////////////////
138 namespace unique_ptr_element_type
{
140 // Test unique_ptr::deleter type
145 typedef bml::unique_ptr
<const int> P
;
146 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::element_type
, const int>::value
));
148 //Unbounded array unique_ptr
150 typedef bml::unique_ptr
<const int[]> P
;
151 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::element_type
, const int>::value
));
153 //Bounded array unique_ptr
155 typedef bml::unique_ptr
<const int[2]> P
;
156 BOOST_STATIC_ASSERT((bmupmu::is_same
<P::element_type
, const int>::value
));
160 } //namespace unique_ptr_element_type {
162 ////////////////////////////////
163 // unique_ptr_construct_assign_traits
164 ////////////////////////////////
166 namespace unique_ptr_construct_assign_traits
{
170 typedef bml::unique_ptr
<int> unique_ptr_t
;
171 //Even if BOOST_MOVE_TT_CXX11_IS_COPY_CONSTRUCTIBLE is not defined
172 //boost::unique_ptr shall work with boost::movelib traits
173 BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible
<unique_ptr_t
>::value
));
174 //Even if BOOST_MOVE_TT_CXX11_IS_COPY_ASSIGNABLE is not defined
175 //boost::unique_ptr shall work with boost::movelib traits
176 BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable
<unique_ptr_t
>::value
));
177 //Important traits for containers like boost::vector
178 BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible
<unique_ptr_t
>::value
));
179 BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable
<unique_ptr_t
>::value
));
182 } //namespace unique_ptr_construct_assign_traits {
184 ////////////////////////////////
186 ////////////////////////////////
191 unique_ptr_pointer_type::test();
192 unique_ptr_deleter_type::test();
193 unique_ptr_element_type::test();
194 unique_ptr_construct_assign_traits::test();
197 return boost::report_errors();
200 #include "unique_ptr_test_utils_end.hpp"