From 626efad30761d1ad436e2cc0d5d98d4e11fed7eb Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 30 Dec 2021 09:39:45 +0800 Subject: [PATCH] spdlog: fmt - support `std::span` in `to_hex` `std::span` does not have `const_iterator`. this prevents `to_hex` from being used with `std::span<>`. to fix this, we provide an explicit overload. compare: https://cplusplus.github.io/LWG/issue3320 --- include/spdlog/fmt/bin_to_hex.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 14908310..76dcb836 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -8,6 +8,14 @@ #include #include +#if defined(__has_include) && __has_include() +#include +#endif + +#if __cpp_lib_span >= 202002L +#include +#endif + // // Support for logging binary data as hex // format flags, any combination of the following: @@ -68,6 +76,19 @@ inline details::dump_info to_hex(const Conta return details::dump_info(std::begin(container), std::end(container), size_per_line); } +#if __cpp_lib_span >= 202002L + +template +inline details::dump_info::iterator> to_hex(const std::span &container, size_t size_per_line = 32) +{ + using Container = std::span; + static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1"); + using Iter = typename Container::iterator; + return details::dump_info(std::begin(container), std::end(container), size_per_line); +} + +#endif + // create dump_info from ranges template inline details::dump_info to_hex(const It range_begin, const It range_end, size_t size_per_line = 32)