From fe734a3072af8a5e8c7b4a8aeafed373dbaf0df2 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 7 Jun 2020 18:38:55 +0300 Subject: [PATCH] c++14 --- CMakeLists.txt | 4 +- example/example.cpp | 8 +-- include/spdlog/common.h | 18 ------ include/spdlog/pattern_formatter.h | 2 +- include/spdlog/version.h | 6 +- src/base_sink.cpp | 4 +- src/logger.cpp | 3 +- src/pattern_formatter.cpp | 92 +++++++++++++++--------------- src/registry.cpp | 2 +- src/stdout_sinks.cpp | 2 +- 10 files changed, 62 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 947016dd..d19cac06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.2) if (${CMAKE_VERSION} VERSION_LESS 3.11) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else () - cmake_policy(VERSION 3.14) + cmake_policy(VERSION 3.11) endif () enable_language(C) @@ -34,7 +34,7 @@ endif () # Compiler config # --------------------------------------------------------------------------------------- if (NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif () diff --git a/example/example.cpp b/example/example.cpp index ef8f23ff..5136eff5 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -257,6 +257,7 @@ void android_example() // Log patterns can contain custom flags. // this will add custom flag '%*' which will be bound to a instance #include "spdlog/pattern_formatter.h" +#include class my_formatter_flag : public spdlog::custom_flag_formatter { public: @@ -268,15 +269,14 @@ public: std::unique_ptr clone() const override { - return spdlog::details::make_unique(); + return std::make_unique(); } }; void custom_flags_example() { - - using spdlog::details::make_unique; // for pre c++14 - auto formatter = make_unique(); + + auto formatter = std::make_unique(); formatter->add_flag('*').set_pattern("[%n] [%*] [%^%l%$] %v"); spdlog::set_formatter(std::move(formatter)); } diff --git a/include/spdlog/common.h b/include/spdlog/common.h index beadd559..a29ed507 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -209,21 +208,4 @@ struct source_loc const char *funcname{nullptr}; }; -namespace details { -// make_unique support for pre c++14 - -#if __cplusplus >= 201402L // C++14 and beyond -using std::make_unique; -#define SPDLOG_VALIDATE_FMT(f) FMT_STRING(f) -#else -#define SPDLOG_VALIDATE_FMT(f) FMT_STRING(f) - -template -std::unique_ptr make_unique(Args &&... args) -{ - static_assert(!std::is_array::value, "arrays not supported"); - return std::unique_ptr(new T(std::forward(args)...)); -} -#endif -} // namespace details } // namespace spdlog diff --git a/include/spdlog/pattern_formatter.h b/include/spdlog/pattern_formatter.h index ebed5917..0b2ff459 100644 --- a/include/spdlog/pattern_formatter.h +++ b/include/spdlog/pattern_formatter.h @@ -94,7 +94,7 @@ public: template pattern_formatter &add_flag(char flag, const Args &... args) { - custom_handlers_[flag] = details::make_unique(args...); + custom_handlers_[flag] = std::make_unique(args...); return *this; } void set_pattern(std::string pattern); diff --git a/include/spdlog/version.h b/include/spdlog/version.h index 66c18296..d216f7a3 100644 --- a/include/spdlog/version.h +++ b/include/spdlog/version.h @@ -3,8 +3,8 @@ #pragma once -#define SPDLOG_VER_MAJOR 1 -#define SPDLOG_VER_MINOR 6 -#define SPDLOG_VER_PATCH 1 +#define SPDLOG_VER_MAJOR 2 +#define SPDLOG_VER_MINOR 0 +#define SPDLOG_VER_PATCH 0 #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) diff --git a/src/base_sink.cpp b/src/base_sink.cpp index fadf73a8..6016749c 100644 --- a/src/base_sink.cpp +++ b/src/base_sink.cpp @@ -10,7 +10,7 @@ template SPDLOG_INLINE spdlog::sinks::base_sink::base_sink() - : formatter_{details::make_unique()} + : formatter_{std::make_unique()} {} template @@ -49,7 +49,7 @@ void SPDLOG_INLINE spdlog::sinks::base_sink::set_formatter(std::unique_pt template void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) { - set_formatter_(details::make_unique(pattern)); + set_formatter_(std::make_unique(pattern)); } template diff --git a/src/logger.cpp b/src/logger.cpp index 20d0ae7e..c7cd18e2 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace spdlog { @@ -96,7 +97,7 @@ SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type) { - auto new_formatter = details::make_unique(std::move(pattern), time_type); + auto new_formatter = std::make_unique(std::move(pattern), time_type); set_formatter(std::move(new_formatter)); } diff --git a/src/pattern_formatter.cpp b/src/pattern_formatter.cpp index 48ed8c48..d842f659 100644 --- a/src/pattern_formatter.cpp +++ b/src/pattern_formatter.cpp @@ -1007,7 +1007,7 @@ SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type, , last_log_secs_(0) { std::memset(&cached_tm_, 0, sizeof(cached_tm_)); - formatters_.push_back(details::make_unique(details::padding_info{})); + formatters_.push_back(std::make_unique(details::padding_info{})); } SPDLOG_INLINE std::unique_ptr pattern_formatter::clone() const @@ -1017,7 +1017,7 @@ SPDLOG_INLINE std::unique_ptr pattern_formatter::clone() const { cloned_custom_formatters[it.first] = it.second->clone(); } - return details::make_unique(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters)); + return std::make_unique(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters)); } SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest) @@ -1069,178 +1069,178 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i switch (flag) { case ('+'): // default formatter - formatters_.push_back(details::make_unique(padding)); + formatters_.push_back(std::make_unique(padding)); break; case 'n': // logger name - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case 'l': // level - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case 'L': // short level - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('t'): // thread id - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('v'): // the message text - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('a'): // weekday - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('A'): // short weekday - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('b'): case ('h'): // month - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('B'): // short month - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('c'): // datetime - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('C'): // year 2 digits - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('Y'): // year 4 digits - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('D'): case ('x'): // datetime MM/DD/YY - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('m'): // month 1-12 - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('d'): // day of month 1-31 - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('H'): // hours 24 - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('I'): // hours 12 - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('M'): // minutes - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('S'): // seconds - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('e'): // milliseconds - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('f'): // microseconds - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('F'): // nanoseconds - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('E'): // seconds since epoch - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('p'): // am/pm - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('r'): // 12 hour clock 02:55:02 pm - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('R'): // 24-hour HH:MM time - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('T'): case ('X'): // ISO 8601 time format (HH:MM:SS) - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('z'): // timezone - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('P'): // pid - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('^'): // color range start - formatters_.push_back(details::make_unique(padding)); + formatters_.push_back(std::make_unique(padding)); break; case ('$'): // color range end - formatters_.push_back(details::make_unique(padding)); + formatters_.push_back(std::make_unique(padding)); break; case ('@'): // source location (filename:filenumber) - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('s'): // short source filename - without directory name - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('g'): // full source filename - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('#'): // source line number - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('!'): // source funcname - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('%'): // % char - formatters_.push_back(details::make_unique('%')); + formatters_.push_back(std::make_unique('%')); break; case ('u'): // elapsed time since last log message in nanos - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('i'): // elapsed time since last log message in micros - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('o'): // elapsed time since last log message in millis - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; case ('O'): // elapsed time since last log message in seconds - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back(std::make_unique>(padding)); break; default: // Unknown flag appears as is - auto unknown_flag = details::make_unique(); + auto unknown_flag = std::make_unique(); unknown_flag->add_ch('%'); unknown_flag->add_ch(flag); formatters_.push_back((std::move(unknown_flag))); @@ -1340,7 +1340,7 @@ SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &patter { if (!user_chars) { - user_chars = details::make_unique(); + user_chars = std::make_unique(); } user_chars->add_ch(*it); } diff --git a/src/registry.cpp b/src/registry.cpp index 2d783ccf..eff47654 100644 --- a/src/registry.cpp +++ b/src/registry.cpp @@ -183,7 +183,7 @@ SPDLOG_INLINE void registry::flush_every(std::chrono::seconds interval) { std::lock_guard lock(flusher_mutex_); auto clbk = [this]() { this->flush_all(); }; - periodic_flusher_ = details::make_unique(clbk, interval); + periodic_flusher_ = std::make_unique(clbk, interval); } SPDLOG_INLINE void registry::set_error_handler(void (*handler)(const std::string &msg)) diff --git a/src/stdout_sinks.cpp b/src/stdout_sinks.cpp index b4876681..67c121a0 100644 --- a/src/stdout_sinks.cpp +++ b/src/stdout_sinks.cpp @@ -18,7 +18,7 @@ template SPDLOG_INLINE stdout_sink_base::stdout_sink_base(FILE *file) : mutex_(ConsoleMutex::mutex()) , file_(file) - , formatter_(details::make_unique()) + , formatter_(std::make_unique()) {} template