more restrictive type conversions

pull/2687/head
Bailey Chittle 3 years ago
parent 6be381bf20
commit 2d0448318e

@ -395,9 +395,36 @@ void replace_default_logger_example()
void attribute_example() {
spdlog::push_context(spdlog::attribute_list{{"attribute_key", "attribute value"}});
spdlog::warn("EXPERIMENTAL: log with attributes");
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<unsigned int&>(x2) }});
spdlog::push_context({{"long", x3 }});
spdlog::push_context({{"ulong", x4 }});
spdlog::push_context({{"llong", x5 }});
spdlog::push_context({{"ullong", x6 }});
// chars shouldnt work?
// spdlog::push_context({{"char", 'a' }});
// floats shouldnt work
// spdlog::push_context({{"float", 1.0f }});
// spdlog::push_context({{"double", 1.0 }});
// bools also shouldnt work
// spdlog::push_context({{"bool", true }});
spdlog::warn("Oops I forgot to clear the context. What will happen?");
// structured logging using attributes
// auto s_logger = spdlog::basic_logger_mt("structured logger", "logs/mylog.txt");

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <string_view>
// #include <string_view>
#include <vector>
#include "attr_composer.h"
#include <spdlog/common.h>
@ -15,7 +15,12 @@ struct is_string
{};
template<typename T>
struct is_number : public std::integral_constant<bool, std::is_integral<T>::value || std::is_floating_point<T>::value>
struct is_number : public std::integral_constant<bool,
std::is_same<T, int>::value || std::is_same<T, unsigned int>::value
|| std::is_same<T, long>::value || std::is_same<T, unsigned long>::value
|| std::is_same<T, long long>::value || std::is_same<T, unsigned long long>::value
// || std::is_floating_point<T>::value
>
{};
struct attr

Loading…
Cancel
Save