From cedfeeb95f3af11df7d3b1e7e0d3b86b334dc23b Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 14 Aug 2023 13:19:02 +0800 Subject: [PATCH] Add SPDLOG_TO_VERSION to compare spdlog version (#2853) You can use SPDLOG_VERSION to select the latest spdlog features where available while falling back to older implementations otherwise. Using SPDLOG_TO_VERSION() for the value to compare with is recommended. for Example: ```c++ void sink_it_(const details::log_msg &msg) override { #if SPDLOG_VERSION < SPDLOG_TO_VERSION(1,4,0) fmt::memory_buffer formatted; #else memory_buf_t formatted; #endif sinks::base_sink::formatter_->format(msg, formatted); // bala bala... } ``` --- include/spdlog/version.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/spdlog/version.h b/include/spdlog/version.h index 633cddc7..ab05e8dd 100644 --- a/include/spdlog/version.h +++ b/include/spdlog/version.h @@ -7,4 +7,5 @@ #define SPDLOG_VER_MINOR 12 #define SPDLOG_VER_PATCH 0 -#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) +#define SPDLOG_TO_VERSION(major, minor, patch) (major * 10000 + minor * 100 + patch) +#define SPDLOG_VERSION SPDLOG_TO_VERSION(SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH)