From b41a6188878f50feace5354b5d71fbe0cd394a87 Mon Sep 17 00:00:00 2001 From: Bailey Chittle Date: Wed, 15 Mar 2023 13:28:30 -0400 Subject: [PATCH] allow shorts to be implicitly converted to int --- example/example.cpp | 30 +++++++++++++++++------------- include/spdlog/details/log_attr.h | 4 ++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index e1416b3e..2ffc354b 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -398,19 +398,23 @@ void attribute_example() { spdlog::info("EXPERIMENTAL: log with attributes"); spdlog::clear_context(); - const int& x1 = 1; - unsigned int x2 = 2; - long x3 = 3; - unsigned long x4 = 4; - long long x5 = 5; - unsigned long long x6 = 6; - spdlog::push_context({{"int_key", x1 }}); - spdlog::push_context({{"uint_key", x2 }}); - spdlog::push_context({{"uint_ref_key", static_cast(x2) }}); - spdlog::push_context({{"long", x3 }}); - spdlog::push_context({{"ulong", x4 }}); - spdlog::push_context({{"llong", x5 }}); - spdlog::push_context({{"ullong", x6 }}); + short s = 0; + unsigned short us = 1; + const int& i = 2; + unsigned int ui = 3; + long l = 4; + unsigned long ul = 5; + long long ll = 6; + unsigned long long ull = 7; + spdlog::push_context({{"short_key", s }}); + spdlog::push_context({{"ushort_key", us }}); + spdlog::push_context({{"int_key", i }}); + spdlog::push_context({{"uint_key", ui }}); + spdlog::push_context({{"uint_ref_key", static_cast(ui) }}); + spdlog::push_context({{"long", l }}); + spdlog::push_context({{"ulong", ul }}); + spdlog::push_context({{"llong", ll }}); + spdlog::push_context({{"ullong", ull }}); // chars shouldnt work? // spdlog::push_context({{"char", 'a' }}); diff --git a/include/spdlog/details/log_attr.h b/include/spdlog/details/log_attr.h index 64f9eed0..0a547619 100644 --- a/include/spdlog/details/log_attr.h +++ b/include/spdlog/details/log_attr.h @@ -19,6 +19,10 @@ struct is_number : public std::integral_constant::value || std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value + + // shorts/chars get converted to int by to_string implicitly. Should we ignore chars but enforce shorts? + || std::is_convertible::value || std::is_convertible::value + // || std::is_floating_point::value > {};