using __ptr_traits_elem_t = typename __ptr_traits_elem<_Ptr>::type;
#endif
// Define pointer_traits::pointer_to.
template::value>
struct __ptr_traits_ptr_to
{
using pointer = _Ptr;
using element_type = _Elt;
/**
* @brief Obtain a pointer to an object
* @param __r A reference to an object of type `element_type`
* @return `pointer::pointer_to(__e)`
* @pre `pointer::pointer_to(__e)` is a valid expression.
*/
static pointer
pointer_to(element_type& __e)
#if __cpp_lib_concepts
requires requires {
{ pointer::pointer_to(__e) } -> convertible_to;
}
#endif
{ return pointer::pointer_to(__e); }
};
// Do not define pointer_traits::pointer_to if element type is void.
template
struct __ptr_traits_ptr_to<_Ptr, _Elt, true>
{ };
// Partial specialization defining pointer_traits::pointer_to(T&).
template
struct __ptr_traits_ptr_to<_Tp*, _Tp, false>
{
using pointer = _Tp*;
using element_type = _Tp;
/**
* @brief Obtain a pointer to an object
* @param __r A reference to an object of type `element_type`
* @return `addressof(__r)`
*/
static _GLIBCXX20_CONSTEXPR pointer
pointer_to(element_type& __r) noexcept
{ return std::addressof(__r); }
};
template
struct __ptr_traits_impl : __ptr_traits_ptr_to<_Ptr, _Elt>
{
private:
template
struct __difference { using type = ptrdiff_t; };
template
#if __cpp_concepts
requires requires { typename _Tp::difference_type; }
struct __difference<_Tp>
#else
struct __difference<_Tp, __void_t>
#endif
{ using type = typename _Tp::difference_type; };
template
struct __rebind : __replace_first_arg<_Tp, _Up> { };
template
#if __cpp_concepts
requires requires { typename _Tp::template rebind<_Up>; }
struct __rebind<_Tp, _Up>
#else
struct __rebind<_Tp, _Up, __void_t>>
#endif
{ using type = typename _Tp::template rebind<_Up>; };
public:
/// The pointer type.
using pointer = _Ptr;
/// The type pointed to.
using element_type = _Elt;
/// The type used to represent the difference between two pointers.
using difference_type = typename __difference<_Ptr>::type;
/// A pointer to a different type.
template
using rebind = typename __rebind<_Ptr, _Up>::type;
};
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 3545. std::pointer_traits should be SFINAE-friendly
template
struct __ptr_traits_impl<_Ptr, __undefined>
{ };
/**
* @brief Uniform interface to all pointer-like types
* @ingroup pointer_abstractions
* @since C++11
*/
template
struct pointer_traits : __ptr_traits_impl<_Ptr, __ptr_traits_elem_t<_Ptr>>
{ };
#if __cpp_concepts
template requires requires { typename _Ptr::element_type; }
struct pointer_traits<_Ptr>
: __ptr_traits_impl<_Ptr, typename _Ptr::element_type>
{ };
#endif
/**
* @brief Partial specialization for built-in pointers.
* @ingroup pointer_abstractions
* @since C++11
*/
template
struct pointer_traits<_Tp*> : __ptr_traits_ptr_to<_Tp*, _Tp>
{
/// The pointer type
typedef _Tp* pointer;
/// The type pointed to
typedef _Tp element_type;
/// Type used to represent the difference between two pointers
typedef ptrdiff_t difference_type;
/// A pointer to a different type.
template using rebind = _Up*;
};
/// Convenience alias for rebinding pointers.
template
using __ptr_rebind = typename pointer_traits<_Ptr>::template rebind<_Tp>;
template
constexpr _Tp*
__to_address(_Tp* __ptr) noexcept
{
static_assert(!std::is_function<_Tp>::value, "not a function pointer");
return __ptr;
}
#if __cplusplus <= 201703L
template
constexpr typename std::pointer_traits<_Ptr>::element_type*
__to_address(const _Ptr& __ptr)
{ return std::__to_address(__ptr.operator->()); }
#else
template
constexpr auto
__to_address(const _Ptr& __ptr) noexcept
-> decltype(std::pointer_traits<_Ptr>::to_address(__ptr))
{ return std::pointer_traits<_Ptr>::to_address(__ptr); }
template
constexpr auto
__to_address(const _Ptr& __ptr, _None...) noexcept
{
if constexpr (is_base_of_v<__gnu_debug::_Safe_iterator_base, _Ptr>)
return std::__to_address(__ptr.base().operator->());
else
return std::__to_address(__ptr.operator->());
}
#define __cpp_lib_to_address 201711L
/**
* @brief Obtain address referenced by a pointer to an object
* @param __ptr A pointer to an object
* @return @c __ptr
* @ingroup pointer_abstractions
*/
template
constexpr _Tp*
to_address(_Tp* __ptr) noexcept
{ return std::__to_address(__ptr); }
/**
* @brief Obtain address referenced by a pointer to an object
* @param __ptr A pointer to an object
* @return @c pointer_traits<_Ptr>::to_address(__ptr) if that expression is
well-formed, otherwise @c to_address(__ptr.operator->())
* @ingroup pointer_abstractions
*/
template
constexpr auto
to_address(const _Ptr& __ptr) noexcept
{ return std::__to_address(__ptr); }
#endif // C++2a
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif
#endif