From 6f8cbefbf2c316a1870a937ea7d91f613554bb03 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Fri, 25 Nov 2016 21:57:26 +0300 Subject: [PATCH] Cleanup to_hex_array.hpp --- .../stacktrace/detail/backend_windows.hpp | 1 - .../boost/stacktrace/detail/to_hex_array.hpp | 25 +++---------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/include/boost/stacktrace/detail/backend_windows.hpp b/include/boost/stacktrace/detail/backend_windows.hpp index 08440c7..3958a54 100644 --- a/include/boost/stacktrace/detail/backend_windows.hpp +++ b/include/boost/stacktrace/detail/backend_windows.hpp @@ -12,7 +12,6 @@ # pragma once #endif -#include #include #include #include diff --git a/include/boost/stacktrace/detail/to_hex_array.hpp b/include/boost/stacktrace/detail/to_hex_array.hpp index 875a3a0..57f8233 100644 --- a/include/boost/stacktrace/detail/to_hex_array.hpp +++ b/include/boost/stacktrace/detail/to_hex_array.hpp @@ -15,31 +15,19 @@ #include #include #include +#include namespace boost { namespace stacktrace { namespace detail { BOOST_STATIC_CONSTEXPR char to_hex_array_bytes[] = "0123456789ABCDEF"; -template -inline bool can_be_safely_trimmed_by(T addr, std::size_t part) BOOST_NOEXCEPT { - return !(addr >> (sizeof(T) / part * 8)); -} - template inline boost::array to_hex_array(T addr) BOOST_NOEXCEPT { boost::array ret = {"0x"}; ret.back() = '\0'; BOOST_STATIC_ASSERT_MSG(!boost::is_pointer::value, ""); - const std::size_t s = ( - can_be_safely_trimmed_by(addr, 2) - ? (can_be_safely_trimmed_by(addr, 4) - ? (can_be_safely_trimmed_by(addr, 8) - ? sizeof(addr) / 8 - : sizeof(addr) / 4) - : sizeof(addr) / 2) - : sizeof(addr) - ); + const std::size_t s = sizeof(T); char* out = ret.data() + s * 2 + 1; @@ -55,16 +43,9 @@ inline boost::array to_hex_array(T addr) BOOST_ return ret; } -inline boost::array to_hex_array(void* addr) BOOST_NOEXCEPT { - return to_hex_array( - reinterpret_cast(addr) - ); -} - - inline boost::array to_hex_array(const void* addr) BOOST_NOEXCEPT { return to_hex_array( - reinterpret_cast(addr) + reinterpret_cast< boost::make_unsigned::type >(addr) ); }