From c79b633a1ca0ad754c6739ea14b6ef8bc5c66aad Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 29 Jan 2023 21:27:53 -0800 Subject: [PATCH] Use std::pointer_traits::to_address when available --- common/almalloc.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/common/almalloc.h b/common/almalloc.h index b73b159b..809f4f1f 100644 --- a/common/almalloc.h +++ b/common/almalloc.h @@ -106,6 +106,17 @@ template constexpr bool operator!=(const allocator&, const allocator&) noexcept { return false; } +namespace detail_ { + template + using void_t = void; + + template + constexpr bool has_to_address = false; + template + constexpr bool has_to_address::to_address(std::declval()))>> = true; +} // namespace detail_ + template constexpr T *to_address(T *p) noexcept { @@ -113,7 +124,11 @@ constexpr T *to_address(T *p) noexcept return p; } -template +template,bool> = true> +constexpr auto to_address(const T& p) noexcept +{ return std::pointer_traits::to_address(p); } + +template,bool> = true> constexpr auto to_address(const T& p) noexcept { return to_address(p.operator->()); }