comparison DEPENDENCIES/generic/include/boost/move/default_delete.hpp @ 102:f46d142149f5

Whoops, finish that update
author Chris Cannam
date Mon, 07 Sep 2015 11:13:41 +0100
parents
children
comparison
equal deleted inserted replaced
101:c530137014c0 102:f46d142149f5
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/move for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_MOVE_DEFAULT_DELETE_HPP_INCLUDED
12 #define BOOST_MOVE_DEFAULT_DELETE_HPP_INCLUDED
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17 #
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/move/detail/config_begin.hpp>
23 #include <boost/move/detail/workaround.hpp>
24 #include <boost/move/detail/unique_ptr_meta_utils.hpp>
25 #include <boost/move/utility_core.hpp>
26 #include <boost/static_assert.hpp>
27
28 #include <cstddef> //For std::size_t,std::nullptr_t
29
30 //!\file
31 //! Describes the default deleter (destruction policy) of <tt>unique_ptr</tt>: <tt>default_delete</tt>.
32
33 namespace boost{
34 namespace move_upd {
35
36 namespace bmupmu = ::boost::move_upmu;
37
38 ////////////////////////////////////////
39 //// enable_def_del
40 ////////////////////////////////////////
41
42 //compatible with a pointer type T*:
43 //When either Y* is convertible to T*
44 //Y is U[N] and T is U cv []
45 template<class U, class T>
46 struct def_del_compatible_cond
47 : bmupmu::is_convertible<U*, T*>
48 {};
49
50 template<class U, class T, std::size_t N>
51 struct def_del_compatible_cond<U[N], T[]>
52 : def_del_compatible_cond<U[], T[]>
53 {};
54
55 template<class U, class T, class Type = bmupmu::nat>
56 struct enable_def_del
57 : bmupmu::enable_if_c<def_del_compatible_cond<U, T>::value, Type>
58 {};
59
60 ////////////////////////////////////////
61 //// enable_defdel_call
62 ////////////////////////////////////////
63
64 //When 2nd is T[N], 1st(*)[N] shall be convertible to T(*)[N];
65 //When 2nd is T[], 1st(*)[] shall be convertible to T(*)[];
66 //Otherwise, 1st* shall be convertible to 2nd*.
67
68 template<class U, class T, class Type = bmupmu::nat>
69 struct enable_defdel_call
70 : public enable_def_del<U, T, Type>
71 {};
72
73 template<class U, class T, class Type>
74 struct enable_defdel_call<U, T[], Type>
75 : public enable_def_del<U[], T[], Type>
76 {};
77
78 template<class U, class T, class Type, std::size_t N>
79 struct enable_defdel_call<U, T[N], Type>
80 : public enable_def_del<U[N], T[N], Type>
81 {};
82
83 ////////////////////////////////////////
84 //// Some bool literal zero conversion utilities
85 ////////////////////////////////////////
86
87 struct bool_conversion {int for_bool; int for_arg(); };
88 typedef int bool_conversion::* explicit_bool_arg;
89
90 #if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_CXX11_DECLTYPE)
91 typedef decltype(nullptr) nullptr_type;
92 #elif !defined(BOOST_NO_CXX11_NULLPTR)
93 typedef std::nullptr_t nullptr_type;
94 #else
95 typedef int (bool_conversion::*nullptr_type)();
96 #endif
97
98 } //namespace move_upd {
99
100 namespace movelib {
101
102 namespace bmupd = boost::move_upd;
103 namespace bmupmu = ::boost::move_upmu;
104
105 //!The class template <tt>default_delete</tt> serves as the default deleter
106 //!(destruction policy) for the class template <tt>unique_ptr</tt>.
107 //!
108 //! \tparam T The type to be deleted. It may be an incomplete type
109 template <class T>
110 struct default_delete
111 {
112 //! Default constructor.
113 //!
114 BOOST_CONSTEXPR default_delete()
115 //Avoid "defaulted on its first declaration must not have an exception-specification" error for GCC 4.6
116 #if !defined(BOOST_GCC) || (BOOST_GCC < 40600 && BOOST_GCC >= 40700) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
117 BOOST_NOEXCEPT
118 #endif
119 #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
120 = default;
121 #else
122 {};
123 #endif
124
125 #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
126 default_delete(const default_delete&) BOOST_NOEXCEPT = default;
127 default_delete &operator=(const default_delete&) BOOST_NOEXCEPT = default;
128 #else
129 typedef typename bmupmu::remove_extent<T>::type element_type;
130 #endif
131
132 //! <b>Effects</b>: Constructs a default_delete object from another <tt>default_delete<U></tt> object.
133 //!
134 //! <b>Remarks</b>: This constructor shall not participate in overload resolution unless:
135 //! - If T is not an array type and U* is implicitly convertible to T*.
136 //! - If T is an array type and U* is a more CV qualified pointer to remove_extent<T>::type.
137 template <class U>
138 default_delete(const default_delete<U>&
139 BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmupd::enable_def_del<U BOOST_MOVE_I T>::type* =0)
140 ) BOOST_NOEXCEPT
141 {
142 //If T is not an array type, U derives from T
143 //and T has no virtual destructor, then you have a problem
144 BOOST_STATIC_ASSERT(( !::boost::move_upmu::missing_virtual_destructor<default_delete, U>::value ));
145 }
146
147 //! <b>Effects</b>: Constructs a default_delete object from another <tt>default_delete<U></tt> object.
148 //!
149 //! <b>Remarks</b>: This constructor shall not participate in overload resolution unless:
150 //! - If T is not an array type and U* is implicitly convertible to T*.
151 //! - If T is an array type and U* is a more CV qualified pointer to remove_extent<T>::type.
152 template <class U>
153 BOOST_MOVE_DOC1ST(default_delete&,
154 typename bmupd::enable_def_del<U BOOST_MOVE_I T BOOST_MOVE_I default_delete &>::type)
155 operator=(const default_delete<U>&) BOOST_NOEXCEPT
156 {
157 //If T is not an array type, U derives from T
158 //and T has no virtual destructor, then you have a problem
159 BOOST_STATIC_ASSERT(( !::boost::move_upmu::missing_virtual_destructor<default_delete, U>::value ));
160 return *this;
161 }
162
163 //! <b>Effects</b>: if T is not an array type, calls <tt>delete</tt> on static_cast<T*>(ptr),
164 //! otherwise calls <tt>delete[]</tt> on static_cast<remove_extent<T>::type*>(ptr).
165 //!
166 //! <b>Remarks</b>: If U is an incomplete type, the program is ill-formed.
167 //! This operator shall not participate in overload resolution unless:
168 //! - T is not an array type and U* is convertible to T*, OR
169 //! - T is an array type, and remove_cv<U>::type is the same type as
170 //! remove_cv<remove_extent<T>::type>::type and U* is convertible to remove_extent<T>::type*.
171 template <class U>
172 BOOST_MOVE_DOC1ST(void, typename bmupd::enable_defdel_call<U BOOST_MOVE_I T BOOST_MOVE_I void>::type)
173 operator()(U* ptr) const BOOST_NOEXCEPT
174 {
175 //U must be a complete type
176 BOOST_STATIC_ASSERT(sizeof(U) > 0);
177 //If T is not an array type, U derives from T
178 //and T has no virtual destructor, then you have a problem
179 BOOST_STATIC_ASSERT(( !::boost::move_upmu::missing_virtual_destructor<default_delete, U>::value ));
180 element_type * const p = static_cast<element_type*>(ptr);
181 bmupmu::is_array<T>::value ? delete [] p : delete p;
182 }
183
184 //! <b>Effects</b>: Same as <tt>(*this)(static_cast<element_type*>(nullptr))</tt>.
185 //!
186 void operator()(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) const BOOST_NOEXCEPT
187 { BOOST_STATIC_ASSERT(sizeof(element_type) > 0); }
188 };
189
190 } //namespace movelib {
191 } //namespace boost{
192
193 #include <boost/move/detail/config_end.hpp>
194
195 #endif //#ifndef BOOST_MOVE_DEFAULT_DELETE_HPP_INCLUDED