From 0d6afd9d5e6291cbd46c4e26d3356ce08fe969ff Mon Sep 17 00:00:00 2001 From: Bailey Chittle Date: Fri, 10 Mar 2023 14:19:27 -0500 Subject: [PATCH] matching the overloads from popular compilers --- include/spdlog/details/log_attr.h | 34 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/include/spdlog/details/log_attr.h b/include/spdlog/details/log_attr.h index 6ef37952..181e6ed4 100644 --- a/include/spdlog/details/log_attr.h +++ b/include/spdlog/details/log_attr.h @@ -51,48 +51,46 @@ struct Value // integer types // probably better to do this with templates, but constraints are needed // concepts would be nice here, but spdlog is c++11 + // SFINAE is also an option, but it's a bit more complicated // https://stackoverflow.com/questions/41552514/is-overloading-on-all-of-the-fundamental-integer-types-is-sufficient-to-capture + // basing the types off of MSVC, GCC, and Clang (https://en.cppreference.com/w/cpp/language/types) - // int8_t + // chars are already strings (single character) Value(signed char v) { - _value = std::to_string(v); + _value = v; } - // uint8_t Value(unsigned char v) { - _value = std::to_string(v); - } - // int16_t - Value(short v) { - _value = std::to_string(v); + _value = v; } - // uint16_t - Value(unsigned short v) { - _value = std::to_string(v); - } - // int32_t + + // these are overloads, which match the overloads in to_string for msvc, gcc, and clang Value(int v) { _value = std::to_string(v); } - // uint32_t Value(unsigned int v) { _value = std::to_string(v); } - // int64_t Value(long v) { _value = std::to_string(v); } - // uint64_t Value(unsigned long v) { _value = std::to_string(v); } - // some compilers use long long for int64_t Value(long long v) { _value = std::to_string(v); } - // some compilers use unsigned long long for uint64_t Value(unsigned long long v) { _value = std::to_string(v); } + Value(float v) { + _value = std::to_string(v); + } + Value(double v) { + _value = std::to_string(v); + } + Value(long double v) { + _value = std::to_string(v); + } Value(bool v) { _value = v ? "true" : "false"; }