]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/move/test/unique_ptr_types.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / move / test / unique_ptr_types.cpp
CommitLineData
7c673cae
FG
1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Howard Hinnant 2009
4// (C) Copyright Ion Gaztanaga 2014-2014.
5//
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)
9//
10// See http://www.boost.org/libs/move for documentation.
11//
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>
18
19//////////////////////////////////////////////
20//
21// The initial implementation of these tests
22// was written by Howard Hinnant.
23//
24// These test were later refactored grouping
25// and porting them to Boost.Move.
26//
27// Many thanks to Howard for releasing his C++03
28// unique_ptr implementation with such detailed
29// test cases.
30//
31//////////////////////////////////////////////
32
33#include "unique_ptr_test_utils_beg.hpp"
34
35namespace bml = ::boost::movelib;
36namespace bmupmu = ::boost::move_upmu;
37
38////////////////////////////////
39// unique_ptr_pointer_type
40////////////////////////////////
41namespace unique_ptr_pointer_type {
42
43struct Deleter
44{
45 struct pointer {};
46};
47
48// Test unique_ptr::pointer type
49void test()
50{
51 //Single unique_ptr
52 {
53 typedef bml::unique_ptr<int> P;
54 BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, int*>::value));
55 }
56 {
57 typedef bml::unique_ptr<int, Deleter> P;
58 BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, Deleter::pointer>::value));
59 }
60 //Unbounded array unique_ptr
61 {
62 typedef bml::unique_ptr<int[]> P;
63 BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, int*>::value));
64 }
65 {
66 typedef bml::unique_ptr<int[], Deleter> P;
67 BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, Deleter::pointer>::value));
68 }
69 //Bounded array unique_ptr
70 {
71 typedef bml::unique_ptr<int[5]> P;
72 BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, int*>::value));
73 }
74 {
75 typedef bml::unique_ptr<int[5], Deleter> P;
76 BOOST_STATIC_ASSERT((bmupmu::is_same<P::pointer, Deleter::pointer>::value));
77 }
78}
79
80} //namespace unique_ptr_pointer_type {
81
82////////////////////////////////
83// unique_ptr_deleter_type
84////////////////////////////////
85namespace unique_ptr_deleter_type {
86
87struct Deleter
88{};
89
90// Test unique_ptr::deleter type
91void test()
92{
93 //Single unique_ptr
94 {
95 typedef bml::unique_ptr<int> P;
96 BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, bml::default_delete<int> >::value));
97 }
98 {
99 typedef bml::unique_ptr<int, Deleter> P;
100 BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, Deleter >::value));
101 }
102 //Unbounded array unique_ptr
103 {
104 typedef bml::unique_ptr<int[]> P;
105 BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, bml::default_delete<int[]> >::value));
106 }
107 {
108 typedef bml::unique_ptr<int[], Deleter> P;
109 BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, Deleter >::value));
110 }
111 //Bounded array unique_ptr
112 {
113 typedef bml::unique_ptr<int[2]> P;
114 BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, bml::default_delete<int[2]> >::value));
115 }
116 {
117 typedef bml::unique_ptr<int[2], Deleter> P;
118 BOOST_STATIC_ASSERT((bmupmu::is_same<P::deleter_type, Deleter >::value));
119 }
120}
121
122} //namespace unique_ptr_deleter_type {
123
124////////////////////////////////
125// unique_ptr_element_type
126////////////////////////////////
127namespace unique_ptr_element_type {
128
129// Test unique_ptr::deleter type
130void test()
131{
132 //Single unique_ptr
133 {
134 typedef bml::unique_ptr<const int> P;
135 BOOST_STATIC_ASSERT((bmupmu::is_same<P::element_type, const int>::value));
136 }
137 //Unbounded array unique_ptr
138 {
139 typedef bml::unique_ptr<const int[]> P;
140 BOOST_STATIC_ASSERT((bmupmu::is_same<P::element_type, const int>::value));
141 }
142 //Bounded array unique_ptr
143 {
144 typedef bml::unique_ptr<const int[2]> P;
145 BOOST_STATIC_ASSERT((bmupmu::is_same<P::element_type, const int>::value));
146 }
147}
148
149} //namespace unique_ptr_element_type {
150
151////////////////////////////////
152// unique_ptr_construct_assign_traits
153////////////////////////////////
154
155namespace unique_ptr_construct_assign_traits {
156
157 void test()
158 {
159 typedef bml::unique_ptr<int> unique_ptr_t;
160 //Even if BOOST_MOVE_TT_CXX11_IS_COPY_CONSTRUCTIBLE is not defined
161 //boost::unique_ptr shall work with boost::movelib traits
162 BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible<unique_ptr_t>::value));
163 //Even if BOOST_MOVE_TT_CXX11_IS_COPY_ASSIGNABLE is not defined
164 //boost::unique_ptr shall work with boost::movelib traits
165 BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable<unique_ptr_t>::value));
166 //Important traits for containers like boost::vector
167 BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<unique_ptr_t>::value));
168 BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<unique_ptr_t>::value));
169 }
170
171} //namespace unique_ptr_construct_assign_traits {
172
173////////////////////////////////
174// main
175////////////////////////////////
176
177int main()
178{
179 //General
180 unique_ptr_pointer_type::test();
181 unique_ptr_deleter_type::test();
182 unique_ptr_element_type::test();
183 unique_ptr_construct_assign_traits::test();
184
185 //Test results
186 return boost::report_errors();
187}
188
189#include "unique_ptr_test_utils_end.hpp"