Merge pull request #2228 from timblechmann/feature/to_hex_span_fix

spdlog: fmt - support `std::span` in `to_hex`
This commit is contained in:
Gabi Melman 2021-12-31 01:23:55 +02:00 committed by GitHub
commit 32fedcf90c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,14 @@
#include <cctype>
#include <spdlog/common.h>
#if defined(__has_include) && __has_include(<version>)
#include <version>
#endif
#if __cpp_lib_span >= 202002L
#include <span>
#endif
//
// Support for logging binary data as hex
// format flags, any combination of the following:
@ -68,6 +76,19 @@ inline details::dump_info<typename Container::const_iterator> to_hex(const Conta
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
}
#if __cpp_lib_span >= 202002L
template <typename Value, size_t Extent>
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(const std::span<Value, Extent> &container, size_t size_per_line = 32)
{
using Container = std::span<Value, Extent>;
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
using Iter = typename Container::iterator;
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
}
#endif
// create dump_info from ranges
template<typename It>
inline details::dump_info<It> to_hex(const It range_begin, const It range_end, size_t size_per_line = 32)