Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/intrusive/pointer_traits.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
4 // Software License, Version 1.0. (See accompanying file | 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) | 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 // | 6 // |
7 ////////////////////////////////////////////////////////////////////////////// | 7 ////////////////////////////////////////////////////////////////////////////// |
8 // | 8 // |
9 // (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost | 9 // (C) Copyright Ion Gaztanaga 2011-2014. Distributed under the Boost |
10 // Software License, Version 1.0. (See accompanying file | 10 // Software License, Version 1.0. (See accompanying file |
11 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 11 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
12 // | 12 // |
13 // See http://www.boost.org/libs/intrusive for documentation. | 13 // See http://www.boost.org/libs/intrusive for documentation. |
14 // | 14 // |
15 ////////////////////////////////////////////////////////////////////////////// | 15 ////////////////////////////////////////////////////////////////////////////// |
16 | 16 |
17 #ifndef BOOST_INTRUSIVE_POINTER_TRAITS_HPP | 17 #ifndef BOOST_INTRUSIVE_POINTER_TRAITS_HPP |
18 #define BOOST_INTRUSIVE_POINTER_TRAITS_HPP | 18 #define BOOST_INTRUSIVE_POINTER_TRAITS_HPP |
19 | 19 |
20 #if (defined _MSC_VER) && (_MSC_VER >= 1200) | 20 #include <boost/intrusive/detail/config_begin.hpp> |
21 #include <boost/intrusive/detail/workaround.hpp> | |
22 #include <boost/intrusive/pointer_rebind.hpp> | |
23 #include <boost/intrusive/detail/pointer_element.hpp> | |
24 #include <boost/intrusive/detail/mpl.hpp> | |
25 #include <cstddef> | |
26 | |
27 #if defined(BOOST_HAS_PRAGMA_ONCE) | |
21 # pragma once | 28 # pragma once |
22 #endif | 29 #endif |
23 | 30 |
24 #include <boost/intrusive/detail/config_begin.hpp> | |
25 #include <boost/intrusive/detail/workaround.hpp> | |
26 #include <boost/intrusive/detail/memory_util.hpp> | |
27 #include <boost/type_traits/integral_constant.hpp> | |
28 #include <cstddef> | |
29 | |
30 namespace boost { | 31 namespace boost { |
31 namespace intrusive { | 32 namespace intrusive { |
33 namespace detail { | |
34 | |
35 #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1310) | |
36 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_pointer_to, pointer_to) | |
37 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_dynamic_cast_from, dynamic_cast_from) | |
38 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_static_cast_from, static_cast_from) | |
39 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_const_cast_from, const_cast_from) | |
40 #else | |
41 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_pointer_to, pointer_to) | |
42 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_dynamic_cast_from, dynamic_cast_from) | |
43 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_static_cast_from, static_cast_from) | |
44 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_const_cast_from, const_cast_from) | |
45 #endif | |
46 | |
47 BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(element_type) | |
48 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type) | |
49 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference) | |
50 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(value_traits_ptr) | |
51 | |
52 } //namespace detail { | |
53 | |
32 | 54 |
33 //! pointer_traits is the implementation of C++11 std::pointer_traits class with some | 55 //! pointer_traits is the implementation of C++11 std::pointer_traits class with some |
34 //! extensions like castings. | 56 //! extensions like castings. |
35 //! | 57 //! |
36 //! pointer_traits supplies a uniform interface to certain attributes of pointer-like types. | 58 //! pointer_traits supplies a uniform interface to certain attributes of pointer-like types. |
59 //! | |
60 //! <b>Note</b>: When defining a custom family of pointers or references to be used with BI | |
61 //! library, make sure the public static conversion functions accessed through | |
62 //! the `pointer_traits` interface (`*_cast_from` and `pointer_to`) can | |
63 //! properly convert between const and nonconst referred member types | |
64 //! <b>without the use of implicit constructor calls</b>. It is suggested these | |
65 //! conversions be implemented as function templates, where the template | |
66 //! argument is the type of the object being converted from. | |
37 template <typename Ptr> | 67 template <typename Ptr> |
38 struct pointer_traits | 68 struct pointer_traits |
39 { | 69 { |
40 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED | 70 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED |
41 //!The pointer type | 71 //!The pointer type |
57 //! | 87 //! |
58 //!For portable code for C++03 and C++11, <pre>typename rebind_pointer<U>::type</pre> | 88 //!For portable code for C++03 and C++11, <pre>typename rebind_pointer<U>::type</pre> |
59 //!shall be used instead of rebind<U> to obtain a pointer to U. | 89 //!shall be used instead of rebind<U> to obtain a pointer to U. |
60 template <class U> using rebind = unspecified; | 90 template <class U> using rebind = unspecified; |
61 | 91 |
62 //!Ptr::rebind<U> if such a type exists; otherwise, SomePointer<U, Args> if Ptr is | 92 //!Ptr::reference if such a type exists (non-standard extension); otherwise, element_type & |
63 //!a class template instantiation of the form SomePointer<T, Args>, where Args is zero or | |
64 //!more type arguments ; otherwise, the instantiation of rebind is ill-formed. | |
65 //! | 93 //! |
66 typedef element_type &reference; | 94 typedef unspecified_type reference; |
67 #else | 95 #else |
68 typedef Ptr pointer; | 96 typedef Ptr pointer; |
69 // | 97 // |
70 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT | 98 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT |
71 ( boost::intrusive::detail::, Ptr, element_type | 99 ( boost::intrusive::detail::, Ptr, element_type |
72 , boost::intrusive::detail::first_param<Ptr>) element_type; | 100 , boost::intrusive::detail::first_param<Ptr>) element_type; |
73 // | 101 // |
74 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT | 102 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT |
75 (boost::intrusive::detail::, Ptr, difference_type, std::ptrdiff_t) difference_type; | 103 (boost::intrusive::detail::, Ptr, difference_type, std::ptrdiff_t) difference_type; |
76 // | 104 |
77 typedef typename boost::intrusive::detail::unvoid_ref<element_type>::type reference; | 105 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT |
106 (boost::intrusive::detail::, Ptr, reference, typename boost::intrusive::detail::unvoid_ref<element_type>::type) reference; | |
78 // | 107 // |
79 template <class U> struct rebind_pointer | 108 template <class U> struct rebind_pointer |
80 { | 109 { |
81 typedef typename boost::intrusive::detail::type_rebinder<Ptr, U>::type type; | 110 typedef typename boost::intrusive::pointer_rebind<Ptr, U>::type type; |
82 }; | 111 }; |
83 | 112 |
84 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) | 113 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) |
85 template <class U> using rebind = typename boost::intrusive::detail::type_rebinder<Ptr, U>::type; | 114 template <class U> using rebind = typename boost::intrusive::pointer_rebind<Ptr, U>::type; |
86 #endif | 115 #endif |
87 #endif //#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) | 116 #endif //#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) |
88 | 117 |
89 //! <b>Remark</b>: If element_type is (possibly cv-qualified) void, r type is unspecified; otherwise, | 118 //! <b>Remark</b>: If element_type is (possibly cv-qualified) void, r type is unspecified; otherwise, |
90 //! it is element_type &. | 119 //! it is element_type &. |
91 //! | 120 //! |
92 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling Ptr::pointer_to(r). | 121 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling Ptr::pointer_to(reference). |
93 //! Non-standard extension: If such function does not exist, returns pointer(addressof(r)); | 122 //! Non-standard extension: If such function does not exist, returns pointer(addressof(r)); |
123 //! | |
124 //! <b>Note</b>: For non-conforming compilers only the existence of a member function called | |
125 //! <code>pointer_to</code> is checked. | |
94 static pointer pointer_to(reference r) | 126 static pointer pointer_to(reference r) |
95 { | 127 { |
96 //Non-standard extension, it does not require Ptr::pointer_to. If not present | 128 //Non-standard extension, it does not require Ptr::pointer_to. If not present |
97 //tries to converts &r to pointer. | 129 //tries to converts &r to pointer. |
98 const bool value = boost::intrusive::detail:: | 130 const bool value = boost::intrusive::detail:: |
99 has_member_function_callable_with_pointer_to | 131 has_member_function_callable_with_pointer_to |
100 <Ptr, typename boost::intrusive::detail::unvoid<element_type &>::type>::value; | 132 <Ptr, Ptr (*)(reference)>::value; |
101 ::boost::integral_constant<bool, value> flag; | 133 boost::intrusive::detail::bool_<value> flag; |
102 return pointer_traits::priv_pointer_to(flag, r); | 134 return pointer_traits::priv_pointer_to(flag, r); |
103 } | 135 } |
104 | 136 |
105 //! <b>Remark</b>: Non-standard extension. | 137 //! <b>Remark</b>: Non-standard extension. |
106 //! | 138 //! |
107 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling Ptr::static_cast_from(r). | 139 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling the static template function |
140 //! Ptr::static_cast_from(UPpr/const UPpr &). | |
108 //! If such function does not exist, returns pointer_to(static_cast<element_type&>(*uptr)) | 141 //! If such function does not exist, returns pointer_to(static_cast<element_type&>(*uptr)) |
142 //! | |
143 //! <b>Note</b>: For non-conforming compilers only the existence of a member function called | |
144 //! <code>static_cast_from</code> is checked. | |
109 template<class UPtr> | 145 template<class UPtr> |
110 static pointer static_cast_from(const UPtr &uptr) | 146 static pointer static_cast_from(const UPtr &uptr) |
111 { | 147 { |
148 typedef const UPtr &RefArg; | |
112 const bool value = boost::intrusive::detail:: | 149 const bool value = boost::intrusive::detail:: |
113 has_member_function_callable_with_static_cast_from | 150 has_member_function_callable_with_static_cast_from |
114 <Ptr, const UPtr>::value; | 151 <pointer, pointer(*)(RefArg)>::value |
115 ::boost::integral_constant<bool, value> flag; | 152 || boost::intrusive::detail:: |
116 return pointer_traits::priv_static_cast_from(flag, uptr); | 153 has_member_function_callable_with_static_cast_from |
154 <pointer, pointer(*)(UPtr)>::value; | |
155 return pointer_traits::priv_static_cast_from(boost::intrusive::detail::bool_<value>(), uptr); | |
117 } | 156 } |
118 | 157 |
119 //! <b>Remark</b>: Non-standard extension. | 158 //! <b>Remark</b>: Non-standard extension. |
120 //! | 159 //! |
121 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling Ptr::const_cast_from(r). | 160 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling the static template function |
161 //! Ptr::const_cast_from<UPtr>(UPpr/const UPpr &). | |
122 //! If such function does not exist, returns pointer_to(const_cast<element_type&>(*uptr)) | 162 //! If such function does not exist, returns pointer_to(const_cast<element_type&>(*uptr)) |
163 //! | |
164 //! <b>Note</b>: For non-conforming compilers only the existence of a member function called | |
165 //! <code>const_cast_from</code> is checked. | |
123 template<class UPtr> | 166 template<class UPtr> |
124 static pointer const_cast_from(const UPtr &uptr) | 167 static pointer const_cast_from(const UPtr &uptr) |
125 { | 168 { |
169 typedef const UPtr &RefArg; | |
126 const bool value = boost::intrusive::detail:: | 170 const bool value = boost::intrusive::detail:: |
127 has_member_function_callable_with_const_cast_from | 171 has_member_function_callable_with_const_cast_from |
128 <Ptr, const UPtr>::value; | 172 <pointer, pointer(*)(RefArg)>::value |
129 ::boost::integral_constant<bool, value> flag; | 173 || boost::intrusive::detail:: |
130 return pointer_traits::priv_const_cast_from(flag, uptr); | 174 has_member_function_callable_with_const_cast_from |
175 <pointer, pointer(*)(UPtr)>::value; | |
176 return pointer_traits::priv_const_cast_from(boost::intrusive::detail::bool_<value>(), uptr); | |
131 } | 177 } |
132 | 178 |
133 //! <b>Remark</b>: Non-standard extension. | 179 //! <b>Remark</b>: Non-standard extension. |
134 //! | 180 //! |
135 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling Ptr::dynamic_cast_from(r). | 181 //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling the static template function |
182 //! Ptr::dynamic_cast_from<UPtr>(UPpr/const UPpr &). | |
136 //! If such function does not exist, returns pointer_to(*dynamic_cast<element_type*>(&*uptr)) | 183 //! If such function does not exist, returns pointer_to(*dynamic_cast<element_type*>(&*uptr)) |
184 //! | |
185 //! <b>Note</b>: For non-conforming compilers only the existence of a member function called | |
186 //! <code>dynamic_cast_from</code> is checked. | |
137 template<class UPtr> | 187 template<class UPtr> |
138 static pointer dynamic_cast_from(const UPtr &uptr) | 188 static pointer dynamic_cast_from(const UPtr &uptr) |
139 { | 189 { |
190 typedef const UPtr &RefArg; | |
140 const bool value = boost::intrusive::detail:: | 191 const bool value = boost::intrusive::detail:: |
141 has_member_function_callable_with_dynamic_cast_from | 192 has_member_function_callable_with_dynamic_cast_from |
142 <Ptr, const UPtr>::value; | 193 <pointer, pointer(*)(RefArg)>::value |
143 ::boost::integral_constant<bool, value> flag; | 194 || boost::intrusive::detail:: |
144 return pointer_traits::priv_dynamic_cast_from(flag, uptr); | 195 has_member_function_callable_with_dynamic_cast_from |
196 <pointer, pointer(*)(UPtr)>::value; | |
197 return pointer_traits::priv_dynamic_cast_from(boost::intrusive::detail::bool_<value>(), uptr); | |
145 } | 198 } |
146 | 199 |
147 ///@cond | 200 ///@cond |
148 private: | 201 private: |
149 //priv_to_raw_pointer | 202 //priv_to_raw_pointer |
155 static typename pointer_traits<Pointer>::element_type* | 208 static typename pointer_traits<Pointer>::element_type* |
156 to_raw_pointer(const Pointer &p) | 209 to_raw_pointer(const Pointer &p) |
157 { return pointer_traits::to_raw_pointer(p.operator->()); } | 210 { return pointer_traits::to_raw_pointer(p.operator->()); } |
158 | 211 |
159 //priv_pointer_to | 212 //priv_pointer_to |
160 static pointer priv_pointer_to(boost::true_type, typename boost::intrusive::detail::unvoid<element_type>::type& r) | 213 static pointer priv_pointer_to(boost::intrusive::detail::true_, reference r) |
161 { return Ptr::pointer_to(r); } | 214 { return Ptr::pointer_to(r); } |
162 | 215 |
163 static pointer priv_pointer_to(boost::false_type, typename boost::intrusive::detail::unvoid<element_type>::type& r) | 216 static pointer priv_pointer_to(boost::intrusive::detail::false_, reference r) |
164 { return pointer(boost::intrusive::detail::addressof(r)); } | 217 { return pointer(boost::intrusive::detail::addressof(r)); } |
165 | 218 |
166 //priv_static_cast_from | 219 //priv_static_cast_from |
167 template<class UPtr> | 220 template<class UPtr> |
168 static pointer priv_static_cast_from(boost::true_type, const UPtr &uptr) | 221 static pointer priv_static_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) |
169 { return Ptr::static_cast_from(uptr); } | 222 { return Ptr::static_cast_from(uptr); } |
170 | 223 |
171 template<class UPtr> | 224 template<class UPtr> |
172 static pointer priv_static_cast_from(boost::false_type, const UPtr &uptr) | 225 static pointer priv_static_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) |
173 { return pointer_to(*static_cast<element_type*>(to_raw_pointer(uptr))); } | 226 { return pointer_to(*static_cast<element_type*>(to_raw_pointer(uptr))); } |
174 | 227 |
175 //priv_const_cast_from | 228 //priv_const_cast_from |
176 template<class UPtr> | 229 template<class UPtr> |
177 static pointer priv_const_cast_from(boost::true_type, const UPtr &uptr) | 230 static pointer priv_const_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) |
178 { return Ptr::const_cast_from(uptr); } | 231 { return Ptr::const_cast_from(uptr); } |
179 | 232 |
180 template<class UPtr> | 233 template<class UPtr> |
181 static pointer priv_const_cast_from(boost::false_type, const UPtr &uptr) | 234 static pointer priv_const_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) |
182 { return pointer_to(const_cast<element_type&>(*uptr)); } | 235 { return pointer_to(const_cast<element_type&>(*uptr)); } |
183 | 236 |
184 //priv_dynamic_cast_from | 237 //priv_dynamic_cast_from |
185 template<class UPtr> | 238 template<class UPtr> |
186 static pointer priv_dynamic_cast_from(boost::true_type, const UPtr &uptr) | 239 static pointer priv_dynamic_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) |
187 { return Ptr::dynamic_cast_from(uptr); } | 240 { return Ptr::dynamic_cast_from(uptr); } |
188 | 241 |
189 template<class UPtr> | 242 template<class UPtr> |
190 static pointer priv_dynamic_cast_from(boost::false_type, const UPtr &uptr) | 243 static pointer priv_dynamic_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) |
191 { return pointer_to(*dynamic_cast<element_type*>(&*uptr)); } | 244 { |
245 element_type *p = dynamic_cast<element_type*>(&*uptr); | |
246 if(!p){ | |
247 return pointer(); | |
248 } | |
249 else{ | |
250 return pointer_to(*p); | |
251 } | |
252 } | |
192 ///@endcond | 253 ///@endcond |
193 }; | 254 }; |
194 | 255 |
195 ///@cond | 256 ///@cond |
196 | 257 |