31#define _PTR_TRAITS_H 1
33#if __cplusplus >= 201103L
37#if __cplusplus > 201703L
39# ifndef __cpp_lib_constexpr_memory
41# define __cpp_lib_constexpr_memory 201811L
43namespace __gnu_debug {
struct _Safe_iterator_base; }
46namespace std _GLIBCXX_VISIBILITY(default)
48_GLIBCXX_BEGIN_NAMESPACE_VERSION
54 template<
typename _Tp>
55 struct __get_first_arg
56 {
using type = __undefined; };
58 template<
template<
typename,
typename...>
class _SomeTemplate,
typename _Tp,
60 struct __get_first_arg<_SomeTemplate<_Tp, _Types...>>
61 {
using type = _Tp; };
65 template<
typename _Tp,
typename _Up>
66 struct __replace_first_arg
69 template<
template<
typename,
typename...>
class _SomeTemplate,
typename _Up,
70 typename _Tp,
typename... _Types>
71 struct __replace_first_arg<_SomeTemplate<_Tp, _Types...>, _Up>
72 {
using type = _SomeTemplate<_Up, _Types...>; };
77 template<
typename _Ptr>
78 using __ptr_traits_elem_t =
typename __get_first_arg<_Ptr>::type;
81 template<
typename _Ptr,
typename =
void>
82 struct __ptr_traits_elem : __get_first_arg<_Ptr>
86 template<
typename _Ptr>
87 struct __ptr_traits_elem<_Ptr, __void_t<typename _Ptr::element_type>>
88 {
using type =
typename _Ptr::element_type; };
90 template<
typename _Ptr>
91 using __ptr_traits_elem_t =
typename __ptr_traits_elem<_Ptr>::type;
95 template<typename _Ptr, typename _Elt, bool = is_void<_Elt>::value>
96 struct __ptr_traits_ptr_to
99 using element_type = _Elt;
108 pointer_to(element_type& __e)
109#if __cpp_lib_concepts
111 { pointer::pointer_to(__e) } -> convertible_to<pointer>;
114 {
return pointer::pointer_to(__e); }
118 template<
typename _Ptr,
typename _Elt>
119 struct __ptr_traits_ptr_to<_Ptr, _Elt, true>
123 template<
typename _Tp>
124 struct __ptr_traits_ptr_to<_Tp*, _Tp,
false>
126 using pointer = _Tp*;
127 using element_type = _Tp;
134 static _GLIBCXX20_CONSTEXPR pointer
135 pointer_to(element_type& __r)
noexcept
139 template<
typename _Ptr,
typename _Elt>
140 struct __ptr_traits_impl : __ptr_traits_ptr_to<_Ptr, _Elt>
143 template<
typename _Tp,
typename =
void>
144 struct __difference {
using type = ptrdiff_t; };
146 template<
typename _Tp>
148 requires requires {
typename _Tp::difference_type; }
149 struct __difference<_Tp>
151 struct __difference<_Tp, __void_t<typename _Tp::difference_type>>
153 {
using type =
typename _Tp::difference_type; };
155 template<
typename _Tp,
typename _Up,
typename =
void>
156 struct __rebind : __replace_first_arg<_Tp, _Up> { };
158 template<
typename _Tp,
typename _Up>
160 requires requires {
typename _Tp::template rebind<_Up>; }
161 struct __rebind<_Tp, _Up>
163 struct __rebind<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>>>
165 {
using type =
typename _Tp::template rebind<_Up>; };
169 using pointer = _Ptr;
172 using element_type = _Elt;
175 using difference_type =
typename __difference<_Ptr>::type;
178 template<
typename _Up>
179 using rebind =
typename __rebind<_Ptr, _Up>::type;
184 template<
typename _Ptr>
185 struct __ptr_traits_impl<_Ptr, __undefined>
193 template<
typename _Ptr>
198 template<
typename _Ptr>
requires requires {
typename _Ptr::element_type; }
199 struct pointer_traits<_Ptr>
200 : __ptr_traits_impl<_Ptr, typename _Ptr::element_type>
209 template<
typename _Tp>
219 template<
typename _Up>
using rebind = _Up*;
223 template<
typename _Ptr,
typename _Tp>
226 template<
typename _Tp>
228 __to_address(_Tp* __ptr)
noexcept
234#if __cplusplus <= 201703L
235 template<
typename _Ptr>
236 constexpr typename std::pointer_traits<_Ptr>::element_type*
237 __to_address(
const _Ptr& __ptr)
238 {
return std::__to_address(__ptr.operator->()); }
240 template<
typename _Ptr>
242 __to_address(
const _Ptr& __ptr)
noexcept
246 template<
typename _Ptr,
typename... _None>
248 __to_address(
const _Ptr& __ptr, _None...) noexcept
250 if constexpr (is_base_of_v<__gnu_debug::_Safe_iterator_base, _Ptr>)
251 return std::__to_address(__ptr.base().operator->());
253 return std::__to_address(__ptr.operator->());
256#define __cpp_lib_to_address 201711L
264 template<
typename _Tp>
267 {
return std::__to_address(__ptr); }
276 template<
typename _Ptr>
279 {
return std::__to_address(__ptr); }
282_GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
ISO C++ entities toplevel namespace is std.
typename pointer_traits< _Ptr >::template rebind< _Tp > __ptr_rebind
Convenience alias for rebinding pointers.
GNU debug classes for public use.
Uniform interface to all pointer-like types.
_Tp * pointer
The pointer type.
ptrdiff_t difference_type
Type used to represent the difference between two pointers.
_Tp element_type
The type pointed to.
_Up * rebind
A pointer to a different type.