Unverified Commit c58b6a08 authored by Joseph Noir's avatar Joseph Noir Committed by GitHub

Merge pull request #862

Allow using meta::hex_formatted for integer types
parents 6620e854 2709eb10
...@@ -19,11 +19,27 @@ ...@@ -19,11 +19,27 @@
#pragma once #pragma once
#include <string> #include <string>
#include <type_traits>
#include "caf/detail/type_traits.hpp"
namespace caf { namespace caf {
namespace detail { namespace detail {
void append_hex(std::string& result, const uint8_t* xs, size_t n); void append_hex(std::string& result, const uint8_t* xs, size_t n);
template <class T>
enable_if_t<has_data_member<T>::value> append_hex(std::string& result,
const T& x) {
return append_hex(result, reinterpret_cast<const uint8_t*>(x.data()),
x.size());
}
template <class T>
enable_if_t<std::is_integral<T>::value> append_hex(std::string& result,
const T& x) {
return append_hex(result, reinterpret_cast<const uint8_t*>(&x), sizeof(T));
}
} // namespace detail } // namespace detail
} // namespace caf } // namespace caf
...@@ -276,8 +276,7 @@ public: ...@@ -276,8 +276,7 @@ public:
template <class T, class... Ts> template <class T, class... Ts>
void traverse(const meta::hex_formatted_t&, const T& x, const Ts&... xs) { void traverse(const meta::hex_formatted_t&, const T& x, const Ts&... xs) {
sep(); sep();
append_hex(result_, reinterpret_cast<uint8_t*>(deconst(x).data()), append_hex(result_, x);
x.size());
traverse(xs...); traverse(xs...);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment