From 4445f6f86900e9ede7f8f111ee3687a693168450 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 16 Mar 2018 17:35:56 +0200 Subject: [PATCH] formatting --- bench/g2log-async.cpp | 3 +- bench/latency/utils.h | 6 +- bench/utils.h | 6 +- example/example.cpp | 3 +- example/jni/example.cpp | 3 +- example/utils.h | 6 +- include/spdlog/details/logger_impl.h | 69 ++-- include/spdlog/details/mpmc_bounded_q.h | 3 +- include/spdlog/details/registry.h | 6 +- include/spdlog/fmt/bundled/format.h | 436 ++++++++++++++++-------- include/spdlog/fmt/bundled/ostream.h | 9 +- include/spdlog/fmt/bundled/printf.h | 63 ++-- include/spdlog/fmt/bundled/time.h | 3 +- include/spdlog/logger.h | 94 +++-- include/spdlog/sinks/ansicolor_sink.h | 9 +- include/spdlog/sinks/base_sink.h | 3 +- include/spdlog/sinks/dist_sink.h | 3 +- include/spdlog/sinks/file_sinks.h | 9 +- include/spdlog/sinks/msvc_sink.h | 3 +- include/spdlog/sinks/null_sink.h | 3 +- include/spdlog/sinks/ostream_sink.h | 3 +- include/spdlog/sinks/stdout_sinks.h | 6 +- include/spdlog/sinks/wincolor_sink.h | 9 +- include/spdlog/sinks/windebug_sink.h | 3 +- include/spdlog/spdlog.h | 9 +- tests/test_misc.cpp | 3 +- 26 files changed, 525 insertions(+), 248 deletions(-) diff --git a/bench/g2log-async.cpp b/bench/g2log-async.cpp index 1a2f2c76..10b4a8c2 100644 --- a/bench/g2log-async.cpp +++ b/bench/g2log-async.cpp @@ -13,7 +13,8 @@ #include "g2logworker.h" using namespace std; -template std::string format(const T &value); +template +std::string format(const T &value); int main(int argc, char *argv[]) { diff --git a/bench/latency/utils.h b/bench/latency/utils.h index 079c5cb8..91610128 100644 --- a/bench/latency/utils.h +++ b/bench/latency/utils.h @@ -11,7 +11,8 @@ namespace utils { -template inline std::string format(const T &value) +template +inline std::string format(const T &value) { static std::locale loc(""); std::stringstream ss; @@ -20,7 +21,8 @@ template inline std::string format(const T &value) return ss.str(); } -template<> inline std::string format(const double &value) +template<> +inline std::string format(const double &value) { static std::locale loc(""); std::stringstream ss; diff --git a/bench/utils.h b/bench/utils.h index 079c5cb8..91610128 100644 --- a/bench/utils.h +++ b/bench/utils.h @@ -11,7 +11,8 @@ namespace utils { -template inline std::string format(const T &value) +template +inline std::string format(const T &value) { static std::locale loc(""); std::stringstream ss; @@ -20,7 +21,8 @@ template inline std::string format(const T &value) return ss.str(); } -template<> inline std::string format(const double &value) +template<> +inline std::string format(const double &value) { static std::locale loc(""); std::stringstream ss; diff --git a/example/example.cpp b/example/example.cpp index 385ed53f..48c4b19e 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -133,7 +133,8 @@ void android_example() struct my_type { int i; - template friend OStream &operator<<(OStream &os, const my_type &c) + template + friend OStream &operator<<(OStream &os, const my_type &c) { return os << "[my_type i=" << c.i << "]"; } diff --git a/example/jni/example.cpp b/example/jni/example.cpp index 385ed53f..48c4b19e 100644 --- a/example/jni/example.cpp +++ b/example/jni/example.cpp @@ -133,7 +133,8 @@ void android_example() struct my_type { int i; - template friend OStream &operator<<(OStream &os, const my_type &c) + template + friend OStream &operator<<(OStream &os, const my_type &c) { return os << "[my_type i=" << c.i << "]"; } diff --git a/example/utils.h b/example/utils.h index 079c5cb8..91610128 100644 --- a/example/utils.h +++ b/example/utils.h @@ -11,7 +11,8 @@ namespace utils { -template inline std::string format(const T &value) +template +inline std::string format(const T &value) { static std::locale loc(""); std::stringstream ss; @@ -20,7 +21,8 @@ template inline std::string format(const T &value) return ss.str(); } -template<> inline std::string format(const double &value) +template<> +inline std::string format(const double &value) { static std::locale loc(""); std::stringstream ss; diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 70eec0e1..38ff0b8f 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -50,7 +50,8 @@ inline void spdlog::logger::set_pattern(const std::string &pattern, pattern_time _set_pattern(pattern, pattern_time); } -template inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Args &... args) +template +inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Args &... args) { if (!should_log(lvl)) return; @@ -77,7 +78,8 @@ template inline void spdlog::logger::log(level::level_enum lvl } } -template inline void spdlog::logger::log(level::level_enum lvl, const char *msg) +template +inline void spdlog::logger::log(level::level_enum lvl, const char *msg) { if (!should_log(lvl)) return; @@ -98,7 +100,8 @@ template inline void spdlog::logger::log(level::level_enum lvl } } -template inline void spdlog::logger::log(level::level_enum lvl, const T &msg) +template +inline void spdlog::logger::log(level::level_enum lvl, const T &msg) { if (!should_log(lvl)) return; @@ -119,62 +122,74 @@ template inline void spdlog::logger::log(level::level_enum lvl, cons } } -template inline void spdlog::logger::trace(const char *fmt, const Arg1 &arg1, const Args &... args) +template +inline void spdlog::logger::trace(const char *fmt, const Arg1 &arg1, const Args &... args) { log(level::trace, fmt, arg1, args...); } -template inline void spdlog::logger::debug(const char *fmt, const Arg1 &arg1, const Args &... args) +template +inline void spdlog::logger::debug(const char *fmt, const Arg1 &arg1, const Args &... args) { log(level::debug, fmt, arg1, args...); } -template inline void spdlog::logger::info(const char *fmt, const Arg1 &arg1, const Args &... args) +template +inline void spdlog::logger::info(const char *fmt, const Arg1 &arg1, const Args &... args) { log(level::info, fmt, arg1, args...); } -template inline void spdlog::logger::warn(const char *fmt, const Arg1 &arg1, const Args &... args) +template +inline void spdlog::logger::warn(const char *fmt, const Arg1 &arg1, const Args &... args) { log(level::warn, fmt, arg1, args...); } -template inline void spdlog::logger::error(const char *fmt, const Arg1 &arg1, const Args &... args) +template +inline void spdlog::logger::error(const char *fmt, const Arg1 &arg1, const Args &... args) { log(level::err, fmt, arg1, args...); } -template inline void spdlog::logger::critical(const char *fmt, const Arg1 &arg1, const Args &... args) +template +inline void spdlog::logger::critical(const char *fmt, const Arg1 &arg1, const Args &... args) { log(level::critical, fmt, arg1, args...); } -template inline void spdlog::logger::trace(const T &msg) +template +inline void spdlog::logger::trace(const T &msg) { log(level::trace, msg); } -template inline void spdlog::logger::debug(const T &msg) +template +inline void spdlog::logger::debug(const T &msg) { log(level::debug, msg); } -template inline void spdlog::logger::info(const T &msg) +template +inline void spdlog::logger::info(const T &msg) { log(level::info, msg); } -template inline void spdlog::logger::warn(const T &msg) +template +inline void spdlog::logger::warn(const T &msg) { log(level::warn, msg); } -template inline void spdlog::logger::error(const T &msg) +template +inline void spdlog::logger::error(const T &msg) { log(level::err, msg); } -template inline void spdlog::logger::critical(const T &msg) +template +inline void spdlog::logger::critical(const T &msg) { log(level::critical, msg); } @@ -183,14 +198,16 @@ template inline void spdlog::logger::critical(const T &msg) #include #include -template inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *msg) +template +inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *msg) { std::wstring_convert> conv; log(lvl, conv.to_bytes(msg)); } -template inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args) +template +inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args) { fmt::WMemoryWriter wWriter; @@ -198,32 +215,38 @@ template inline void spdlog::logger::log(level::level_enum lvl log(lvl, wWriter.c_str()); } -template inline void spdlog::logger::trace(const wchar_t *fmt, const Args &... args) +template +inline void spdlog::logger::trace(const wchar_t *fmt, const Args &... args) { log(level::trace, fmt, args...); } -template inline void spdlog::logger::debug(const wchar_t *fmt, const Args &... args) +template +inline void spdlog::logger::debug(const wchar_t *fmt, const Args &... args) { log(level::debug, fmt, args...); } -template inline void spdlog::logger::info(const wchar_t *fmt, const Args &... args) +template +inline void spdlog::logger::info(const wchar_t *fmt, const Args &... args) { log(level::info, fmt, args...); } -template inline void spdlog::logger::warn(const wchar_t *fmt, const Args &... args) +template +inline void spdlog::logger::warn(const wchar_t *fmt, const Args &... args) { log(level::warn, fmt, args...); } -template inline void spdlog::logger::error(const wchar_t *fmt, const Args &... args) +template +inline void spdlog::logger::error(const wchar_t *fmt, const Args &... args) { log(level::err, fmt, args...); } -template inline void spdlog::logger::critical(const wchar_t *fmt, const Args &... args) +template +inline void spdlog::logger::critical(const wchar_t *fmt, const Args &... args) { log(level::critical, fmt, args...); } diff --git a/include/spdlog/details/mpmc_bounded_q.h b/include/spdlog/details/mpmc_bounded_q.h index 427af65c..29ec316b 100644 --- a/include/spdlog/details/mpmc_bounded_q.h +++ b/include/spdlog/details/mpmc_bounded_q.h @@ -50,7 +50,8 @@ Distributed under the MIT License (http://opensource.org/licenses/MIT) namespace spdlog { namespace details { -template class mpmc_bounded_queue +template +class mpmc_bounded_queue { public: using item_type = T; diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 3f500c1e..ac0a58a5 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -23,7 +23,8 @@ #include namespace spdlog { namespace details { -template class registry_t +template +class registry_t { public: registry_t(const registry_t &) = delete; @@ -44,7 +45,8 @@ public: return found == _loggers.end() ? nullptr : found->second; } - template std::shared_ptr create(const std::string &logger_name, const It &sinks_begin, const It &sinks_end) + template + std::shared_ptr create(const std::string &logger_name, const It &sinks_begin, const It &sinks_end) { std::lock_guard lock(_mutex); throw_if_exists(logger_name); diff --git a/include/spdlog/fmt/bundled/format.h b/include/spdlog/fmt/bundled/format.h index 529ffb36..9b2fe3b4 100644 --- a/include/spdlog/fmt/bundled/format.h +++ b/include/spdlog/fmt/bundled/format.h @@ -434,7 +434,8 @@ inline DummyInt _isnan(...) // A helper function to suppress bogus "conditional expression is constant" // warnings. -template inline T const_check(T value) +template +inline T const_check(T value) { return value; } @@ -445,11 +446,13 @@ namespace std { // is used to resolve ambiguity between isinf and std::isinf in glibc: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891 // and the same for isnan and signbit. -template<> class numeric_limits : public std::numeric_limits +template<> +class numeric_limits : public std::numeric_limits { public: // Portable version of isinf. - template static bool isinfinity(T x) + template + static bool isinfinity(T x) { using namespace fmt::internal; // The resolution "priority" is: @@ -462,7 +465,8 @@ public: } // Portable version of isnan. - template static bool isnotanumber(T x) + template + static bool isnotanumber(T x) { using namespace fmt::internal; if (const_check(sizeof(isnan(x)) == sizeof(bool) || sizeof(isnan(x)) == sizeof(int))) @@ -503,18 +507,22 @@ FMT_GCC_EXTENSION typedef unsigned long long ULongLong; using std::move; #endif -template class BasicWriter; +template +class BasicWriter; typedef BasicWriter Writer; typedef BasicWriter WWriter; -template class ArgFormatter; +template +class ArgFormatter; struct FormatSpec; -template class BasicPrintfArgFormatter; +template +class BasicPrintfArgFormatter; -template> class BasicFormatter; +template> +class BasicFormatter; /** \rst @@ -541,7 +549,8 @@ template> format(std::string("{}"), 42); \endrst */ -template class BasicStringRef +template +class BasicStringRef { private: const Char *data_; @@ -688,7 +697,8 @@ typedef BasicStringRef WStringRef; format(std::string("{}"), 42); \endrst */ -template class BasicCStringRef +template +class BasicCStringRef { private: const Char *data_; @@ -739,13 +749,15 @@ public: namespace internal { // MakeUnsigned::Type gives an unsigned type corresponding to integer type T. -template struct MakeUnsigned +template +struct MakeUnsigned { typedef T Type; }; #define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \ - template<> struct MakeUnsigned \ + template<> \ + struct MakeUnsigned \ { \ typedef U Type; \ } @@ -758,7 +770,8 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long); FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong); // Casts nonnegative integer to unsigned. -template inline typename MakeUnsigned::Type to_unsigned(Int value) +template +inline typename MakeUnsigned::Type to_unsigned(Int value) { FMT_ASSERT(value >= 0, "negative value"); return static_cast::Type>(value); @@ -773,12 +786,14 @@ enum #if FMT_SECURE_SCL // Use checked iterator to avoid warnings on MSVC. -template inline stdext::checked_array_iterator make_ptr(T *ptr, std::size_t size) +template +inline stdext::checked_array_iterator make_ptr(T *ptr, std::size_t size) { return stdext::checked_array_iterator(ptr, size); } #else -template inline T *make_ptr(T *ptr, std::size_t) +template +inline T *make_ptr(T *ptr, std::size_t) { return ptr; } @@ -790,7 +805,8 @@ template inline T *make_ptr(T *ptr, std::size_t) A buffer supporting a subset of ``std::vector``'s operations. \endrst */ -template class Buffer +template +class Buffer { private: FMT_DISALLOW_COPY_AND_ASSIGN(Buffer); @@ -864,7 +880,8 @@ public: } /** Appends data to the end of the buffer. */ - template void append(const U *begin, const U *end); + template + void append(const U *begin, const U *end); T &operator[](std::size_t index) { @@ -876,7 +893,9 @@ public: } }; -template template void Buffer::append(const U *begin, const U *end) +template +template +void Buffer::append(const U *begin, const U *end) { FMT_ASSERT(end >= begin, "negative value"); std::size_t new_size = size_ + static_cast(end - begin); @@ -890,7 +909,8 @@ namespace internal { // A memory buffer for trivially copyable/constructible types with the first // SIZE elements stored in the object itself. -template> class MemoryBuffer : private Allocator, public Buffer +template> +class MemoryBuffer : private Allocator, public Buffer { private: T data_[SIZE]; @@ -961,7 +981,8 @@ public: } }; -template void MemoryBuffer::grow(std::size_t size) +template +void MemoryBuffer::grow(std::size_t size) { std::size_t new_capacity = this->capacity_ + this->capacity_ / 2; if (size > new_capacity) @@ -985,7 +1006,8 @@ template void MemoryBuffer class FixedBuffer : public fmt::Buffer +template +class FixedBuffer : public fmt::Buffer { public: FixedBuffer(Char *array, std::size_t size) @@ -997,7 +1019,8 @@ protected: FMT_API void grow(std::size_t size) FMT_OVERRIDE; }; -template class BasicCharTraits +template +class BasicCharTraits { public: #if FMT_SECURE_SCL @@ -1011,9 +1034,11 @@ public: } }; -template class CharTraits; +template +class CharTraits; -template<> class CharTraits : public BasicCharTraits +template<> +class CharTraits : public BasicCharTraits { private: // Conversion from wchar_t to char is not allowed. @@ -1037,7 +1062,8 @@ extern template int CharTraits::format_float( char *buffer, std::size_t size, const char *format, unsigned width, int precision, long double value); #endif -template<> class CharTraits : public BasicCharTraits +template<> +class CharTraits : public BasicCharTraits { public: static wchar_t convert(char value) @@ -1061,17 +1087,21 @@ extern template int CharTraits::format_float( #endif // Checks if a number is negative - used to avoid warnings. -template struct SignChecker +template +struct SignChecker { - template static bool is_negative(T value) + template + static bool is_negative(T value) { return value < 0; } }; -template<> struct SignChecker +template<> +struct SignChecker { - template static bool is_negative(T) + template + static bool is_negative(T) { return false; } @@ -1079,23 +1109,27 @@ template<> struct SignChecker // Returns true if value is negative, false otherwise. // Same as (value < 0) but doesn't produce warnings if T is an unsigned type. -template inline bool is_negative(T value) +template +inline bool is_negative(T value) { return SignChecker::is_signed>::is_negative(value); } // Selects uint32_t if FitsIn32Bits is true, uint64_t otherwise. -template struct TypeSelector +template +struct TypeSelector { typedef uint32_t Type; }; -template<> struct TypeSelector +template<> +struct TypeSelector { typedef uint64_t Type; }; -template struct IntTraits +template +struct IntTraits { // Smallest of uint32_t and uint64_t that is large enough to represent // all values of T. @@ -1106,7 +1140,8 @@ FMT_API FMT_NORETURN void report_unknown_type(char code, const char *type); // Static data is placed in this class template to allow header-only // configuration. -template struct FMT_API BasicData +template +struct FMT_API BasicData { static const uint32_t POWERS_OF_10_32[]; static const uint64_t POWERS_OF_10_64[]; @@ -1165,7 +1200,10 @@ inline unsigned count_digits(uint32_t n) // A functor that doesn't add a thousands separator. struct NoThousandsSep { - template void operator()(Char *) {} + template + void operator()(Char *) + { + } }; // A functor that adds a thousands separator. @@ -1184,7 +1222,8 @@ public: { } - template void operator()(Char *&buffer) + template + void operator()(Char *&buffer) { if (++digit_index_ % 3 != 0) return; @@ -1223,7 +1262,8 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits, Thousa *--buffer = Data::DIGITS[index]; } -template inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) +template +inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) { format_decimal(buffer, value, num_digits, NoThousandsSep()); return; @@ -1304,7 +1344,8 @@ FMT_API void format_windows_error(fmt::Writer &out, int error_code, fmt::StringR // A formatting argument value. struct Value { - template struct StringValue + template + struct StringValue { const Char *value; std::size_t size; @@ -1365,22 +1406,27 @@ struct Arg : Value Type type; }; -template struct NamedArg; -template struct NamedArgWithType; +template +struct NamedArg; +template +struct NamedArgWithType; -template struct Null +template +struct Null { }; // A helper class template to enable or disable overloads taking wide // characters and strings in MakeValue. -template struct WCharHelper +template +struct WCharHelper { typedef Null Supported; typedef T Unsupported; }; -template struct WCharHelper +template +struct WCharHelper { typedef T Supported; typedef Null Unsupported; @@ -1389,13 +1435,15 @@ template struct WCharHelper typedef char Yes[1]; typedef char No[2]; -template T &get(); +template +T &get(); // These are non-members to workaround an overload resolution bug in bcc32. Yes &convert(fmt::ULongLong); No &convert(...); -template struct ConvertToIntImpl +template +struct ConvertToIntImpl { enum { @@ -1403,7 +1451,8 @@ template struct ConvertToIntImpl }; }; -template struct ConvertToIntImpl2 +template +struct ConvertToIntImpl2 { enum { @@ -1411,7 +1460,8 @@ template struct ConvertToIntImpl2 }; }; -template struct ConvertToIntImpl2 +template +struct ConvertToIntImpl2 { enum { @@ -1420,7 +1470,8 @@ template struct ConvertToIntImpl2 }; }; -template struct ConvertToInt +template +struct ConvertToInt { enum { @@ -1433,7 +1484,8 @@ template struct ConvertToInt }; #define FMT_DISABLE_CONVERSION_TO_INT(Type) \ - template<> struct ConvertToInt \ + template<> \ + struct ConvertToInt \ { \ enum \ { \ @@ -1446,27 +1498,32 @@ FMT_DISABLE_CONVERSION_TO_INT(float); FMT_DISABLE_CONVERSION_TO_INT(double); FMT_DISABLE_CONVERSION_TO_INT(long double); -template struct EnableIf +template +struct EnableIf { }; -template struct EnableIf +template +struct EnableIf { typedef T type; }; -template struct Conditional +template +struct Conditional { typedef T type; }; -template struct Conditional +template +struct Conditional { typedef F type; }; // For bcc32 which doesn't understand ! in template arguments. -template struct Not +template +struct Not { enum { @@ -1474,7 +1531,8 @@ template struct Not }; }; -template<> struct Not +template<> +struct Not { enum { @@ -1482,7 +1540,8 @@ template<> struct Not }; }; -template struct FalseType +template +struct FalseType { enum { @@ -1490,7 +1549,8 @@ template struct FalseType }; }; -template struct LConvCheck +template +struct LConvCheck { LConvCheck(int) {} }; @@ -1498,7 +1558,8 @@ template struct LConvCheck // Returns the thousands separator for the current locale. // We check if ``lconv`` contains ``thousands_sep`` because on Android // ``lconv`` is stubbed as an empty struct. -template inline StringRef thousands_sep(LConv *lc, LConvCheck = 0) +template +inline StringRef thousands_sep(LConv *lc, LConvCheck = 0) { return lc->thousands_sep; } @@ -1527,7 +1588,8 @@ inline fmt::StringRef thousands_sep(...) #define FMT_STATIC_ASSERT(cond, message) typedef int FMT_CONCAT_(Assert, __LINE__)[(cond) ? 1 : -1] FMT_UNUSED #endif -template void format_arg(Formatter &, ...) +template +void format_arg(Formatter &, ...) { FMT_STATIC_ASSERT(FalseType::value, "Cannot format argument. To enable the use of ostream " "operator<< include fmt/ostream.h. Otherwise provide " @@ -1535,7 +1597,8 @@ template void format_arg(Formatter &, ...) } // Makes an Arg object from any type. -template class MakeValue : public Arg +template +class MakeValue : public Arg { public: typedef typename Formatter::Char Char; @@ -1546,8 +1609,10 @@ private: // "void *" or "const void *". In particular, this forbids formatting // of "[const] volatile char *" which is printed as bool by iostreams. // Do not implement! - template MakeValue(const T *value); - template MakeValue(T *value); + template + MakeValue(const T *value); + template + MakeValue(T *value); // The following methods are private to disallow formatting of wide // characters and strings into narrow strings as in @@ -1577,7 +1642,8 @@ private: } // Formats an argument of a custom type, such as a user-defined class. - template static void format_custom_arg(void *formatter, const void *arg, void *format_str_ptr) + template + static void format_custom_arg(void *formatter, const void *arg, void *format_str_ptr) { format_arg(*static_cast(formatter), *static_cast(format_str_ptr), *static_cast(arg)); } @@ -1639,12 +1705,14 @@ public: FMT_MAKE_VALUE(char, int_value, CHAR) #if __cplusplus >= 201103L - template::value && ConvertToInt::value>::type> MakeValue(T value) + template::value && ConvertToInt::value>::type> + MakeValue(T value) { int_value = value; } - template::value && ConvertToInt::value>::type> static uint64_t type(T) + template::value && ConvertToInt::value>::type> + static uint64_t type(T) { return Arg::INT; } @@ -1705,39 +1773,46 @@ public: FMT_MAKE_VALUE(void *, pointer, POINTER) FMT_MAKE_VALUE(const void *, pointer, POINTER) - template MakeValue(const T &value, typename EnableIf::value>::value, int>::type = 0) + template + MakeValue(const T &value, typename EnableIf::value>::value, int>::type = 0) { custom.value = &value; custom.format = &format_custom_arg; } - template static typename EnableIf::value>::value, uint64_t>::type type(const T &) + template + static typename EnableIf::value>::value, uint64_t>::type type(const T &) { return Arg::CUSTOM; } // Additional template param `Char_` is needed here because make_type always // uses char. - template MakeValue(const NamedArg &value) + template + MakeValue(const NamedArg &value) { pointer = &value; } - template MakeValue(const NamedArgWithType &value) + template + MakeValue(const NamedArgWithType &value) { pointer = &value; } - template static uint64_t type(const NamedArg &) + template + static uint64_t type(const NamedArg &) { return Arg::NAMED_ARG; } - template static uint64_t type(const NamedArgWithType &) + template + static uint64_t type(const NamedArgWithType &) { return Arg::NAMED_ARG; } }; -template class MakeArg : public Arg +template +class MakeArg : public Arg { public: MakeArg() @@ -1753,7 +1828,8 @@ public: } }; -template struct NamedArg : Arg +template +struct NamedArg : Arg { BasicStringRef name; @@ -1765,7 +1841,8 @@ template struct NamedArg : Arg } }; -template struct NamedArgWithType : NamedArg +template +struct NamedArgWithType : NamedArg { NamedArgWithType(BasicStringRef argname, const T &value) : NamedArg(argname, value) @@ -1787,7 +1864,8 @@ protected: FMT_API ~RuntimeError() FMT_DTOR_NOEXCEPT FMT_OVERRIDE; }; -template class ArgMap; +template +class ArgMap; } // namespace internal /** An argument list. */ @@ -1813,7 +1891,8 @@ private: return type(types_, index); } - template friend class internal::ArgMap; + template + friend class internal::ArgMap; public: // Maximum number of arguments with packed types. @@ -1907,7 +1986,8 @@ public: }; \endrst */ -template class ArgVisitor +template +class ArgVisitor { private: typedef internal::Arg Arg; @@ -1958,7 +2038,8 @@ public: } /** Visits an argument of any integral type. **/ - template Result visit_any_int(T) + template + Result visit_any_int(T) { return FMT_DISPATCH(visit_unhandled_arg()); } @@ -1976,7 +2057,8 @@ public: } /** Visits a ``double`` or ``long double`` argument. **/ - template Result visit_any_double(T) + template + Result visit_any_double(T) { return FMT_DISPATCH(visit_unhandled_arg()); } @@ -2083,7 +2165,8 @@ struct EmptySpec }; // A type specifier. -template struct TypeSpec : EmptySpec +template +struct TypeSpec : EmptySpec { Alignment align() const { @@ -2162,7 +2245,8 @@ struct AlignSpec : WidthSpec }; // An alignment and type specifier. -template struct AlignTypeSpec : AlignSpec +template +struct AlignTypeSpec : AlignSpec { AlignTypeSpec(unsigned width, wchar_t fill) : AlignSpec(width, fill) @@ -2217,7 +2301,8 @@ struct FormatSpec : AlignSpec }; // An integer format specifier. -template, typename Char = char> class IntFormatSpec : public SpecT +template, typename Char = char> +class IntFormatSpec : public SpecT { private: T value_; @@ -2236,7 +2321,8 @@ public: }; // A string format specifier. -template class StrFormatSpec : public AlignSpec +template +class StrFormatSpec : public AlignSpec { private: const Char *str_; @@ -2292,7 +2378,8 @@ IntFormatSpec> hexu(int value); \endrst */ -template IntFormatSpec, Char> pad(int value, unsigned width, Char fill = ' '); +template +IntFormatSpec, Char> pad(int value, unsigned width, Char fill = ' '); #define FMT_DEFINE_INT_FORMATTERS(TYPE) \ inline IntFormatSpec> bin(TYPE value) \ @@ -2337,7 +2424,8 @@ template IntFormatSpec>(value, AlignTypeSpec<0>(width, ' ')); \ } \ \ - template inline IntFormatSpec, Char> pad(TYPE value, unsigned width, Char fill) \ + template \ + inline IntFormatSpec, Char> pad(TYPE value, unsigned width, Char fill) \ { \ return IntFormatSpec, Char>(value, AlignTypeSpec<0>(width, fill)); \ } @@ -2361,7 +2449,8 @@ FMT_DEFINE_INT_FORMATTERS(ULongLong) \endrst */ -template inline StrFormatSpec pad(const Char *str, unsigned width, Char fill = ' ') +template +inline StrFormatSpec pad(const Char *str, unsigned width, Char fill = ' ') { return StrFormatSpec(str, width, fill); } @@ -2373,7 +2462,8 @@ inline StrFormatSpec pad(const wchar_t *str, unsigned width, char fill namespace internal { -template class ArgMap +template +class ArgMap { private: typedef std::vector, internal::Arg>> MapType; @@ -2396,7 +2486,8 @@ public: } }; -template void ArgMap::init(const ArgList &args) +template +void ArgMap::init(const ArgList &args) { if (!map_.empty()) return; @@ -2449,7 +2540,8 @@ template void ArgMap::init(const ArgList &args) } } -template class ArgFormatterBase : public ArgVisitor +template +class ArgFormatterBase : public ArgVisitor { private: BasicWriter &writer_; @@ -2499,12 +2591,14 @@ public: { } - template void visit_any_int(T value) + template + void visit_any_int(T value) { writer_.write_int(value, spec_); } - template void visit_any_double(T value) + template + void visit_any_double(T value) { writer_.write_double(value, spec_); } @@ -2633,7 +2727,8 @@ protected: return true; } - template void write(BasicWriter &w, const Char *start, const Char *end) + template + void write(BasicWriter &w, const Char *start, const Char *end) { if (start != end) w << BasicStringRef(start, internal::to_unsigned(end - start)); @@ -2689,7 +2784,8 @@ public: }; /** The default argument formatter. */ -template class ArgFormatter : public BasicArgFormatter, Char, FormatSpec> +template +class ArgFormatter : public BasicArgFormatter, Char, FormatSpec> { public: /** Constructs an argument formatter object. */ @@ -2700,7 +2796,8 @@ public: }; /** This template formats data and writes the output to a writer. */ -template class BasicFormatter : private internal::FormatterBase +template +class BasicFormatter : private internal::FormatterBase { public: /** The character type for the output. */ @@ -2776,19 +2873,23 @@ inline uint64_t make_type() return 0; } -template inline uint64_t make_type(const T &arg) +template +inline uint64_t make_type(const T &arg) { return MakeValue>::type(arg); } -template struct ArgArray; +template +struct ArgArray; -template struct ArgArray +template +struct ArgArray { // '+' is used to silence GCC -Wduplicated-branches warning. typedef Value Type[N > 0 ? N : +1]; - template static Value make(const T &value) + template + static Value make(const T &value) { #ifdef __clang__ Value result = MakeValue(value); @@ -2802,18 +2903,21 @@ template struct ArgArray } }; -template struct ArgArray +template +struct ArgArray { typedef Arg Type[N + 1]; // +1 for the list end Arg::NONE - template static Arg make(const T &value) + template + static Arg make(const T &value) { return MakeArg(value); } }; #if FMT_USE_VARIADIC_TEMPLATES -template inline uint64_t make_type(const Arg &first, const Args &... tail) +template +inline uint64_t make_type(const Arg &first, const Args &... tail) { return make_type(first) | (make_type(tail...) << 4); } @@ -2856,7 +2960,8 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) #if FMT_USE_VARIADIC_TEMPLATES // Defines a variadic function returning void. #define FMT_VARIADIC_VOID(func, arg_type) \ - template void func(arg_type arg0, const Args &... args) \ + template \ + void func(arg_type arg0, const Args &... args) \ { \ typedef fmt::internal::ArgArray ArgArray; \ typename ArgArray::Type array{ArgArray::template make>(args)...}; \ @@ -2865,7 +2970,8 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) // Defines a variadic constructor. #define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ - template ctor(arg0_type arg0, arg1_type arg1, const Args &... args) \ + template \ + ctor(arg0_type arg0, arg1_type arg1, const Args &... args) \ { \ typedef fmt::internal::ArgArray ArgArray; \ typename ArgArray::Type array{ArgArray::template make>(args)...}; \ @@ -2880,7 +2986,8 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) // Defines a wrapper for a function taking one argument of type arg_type // and n additional arguments of arbitrary types. #define FMT_WRAP1(func, arg_type, n) \ - template inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) \ + template \ + inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) \ { \ const fmt::internal::ArgArray::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \ func(arg1, fmt::ArgList(fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \ @@ -2901,7 +3008,8 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) FMT_WRAP1(func, arg_type, 7) FMT_WRAP1(func, arg_type, 8) FMT_WRAP1(func, arg_type, 9) FMT_WRAP1(func, arg_type, 10) #define FMT_CTOR(ctor, func, arg0_type, arg1_type, n) \ - template ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) \ + template \ + ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) \ { \ const fmt::internal::ArgArray::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \ func(arg0, arg1, fmt::ArgList(fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \ @@ -3020,7 +3128,8 @@ FMT_API void format_system_error(fmt::Writer &out, int error_code, fmt::StringRe \endrst */ -template class BasicWriter +template +class BasicWriter { private: // Output buffer. @@ -3057,7 +3166,8 @@ private: } // Writes an unsigned decimal integer. - template Char *write_unsigned_decimal(UInt value, unsigned prefix_size = 0) + template + Char *write_unsigned_decimal(UInt value, unsigned prefix_size = 0) { unsigned num_digits = internal::count_digits(value); Char *ptr = get(grow_buffer(prefix_size + num_digits)); @@ -3066,7 +3176,8 @@ private: } // Writes a decimal integer. - template void write_decimal(Int value) + template + void write_decimal(Int value) { typedef typename internal::IntTraits::MainType MainType; MainType abs_value = static_cast(value); @@ -3090,18 +3201,23 @@ private: return p + size - 1; } - template CharPtr prepare_int_buffer(unsigned num_digits, const Spec &spec, const char *prefix, unsigned prefix_size); + template + CharPtr prepare_int_buffer(unsigned num_digits, const Spec &spec, const char *prefix, unsigned prefix_size); // Formats an integer. - template void write_int(T value, Spec spec); + template + void write_int(T value, Spec spec); // Formats a floating-point number (double or long double). - template void write_double(T value, const Spec &spec); + template + void write_double(T value, const Spec &spec); // Writes a formatted string. - template CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec); + template + CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec); - template void write_str(const internal::Arg::StringValue &str, const Spec &spec); + template + void write_str(const internal::Arg::StringValue &str, const Spec &spec); // This following methods are private to disallow writing wide characters // and strings to a char stream. If you want to print a wide string as a @@ -3117,11 +3233,16 @@ private: *format_ptr++ = 'L'; } - template void append_float_length(Char *&, T) {} + template + void append_float_length(Char *&, T) + { + } - template friend class internal::ArgFormatterBase; + template + friend class internal::ArgFormatterBase; - template friend class BasicPrintfArgFormatter; + template + friend class BasicPrintfArgFormatter; protected: /** @@ -3296,14 +3417,16 @@ public: return *this; } - template BasicWriter &operator<<(IntFormatSpec spec) + template + BasicWriter &operator<<(IntFormatSpec spec) { internal::CharTraits::convert(FillChar()); write_int(spec.value(), spec); return *this; } - template BasicWriter &operator<<(const StrFormatSpec &spec) + template + BasicWriter &operator<<(const StrFormatSpec &spec) { const StrChar *s = spec.str(); write_str(s, std::char_traits::length(s), spec); @@ -3463,7 +3586,9 @@ typename BasicWriter::CharPtr BasicWriter::prepare_int_buffer( return p - 1; } -template template void BasicWriter::write_int(T value, Spec spec) +template +template +void BasicWriter::write_int(T value, Spec spec) { unsigned prefix_size = 0; typedef typename internal::IntTraits::MainType UnsignedType; @@ -3571,7 +3696,9 @@ template template void BasicWriter template void BasicWriter::write_double(T value, const Spec &spec) +template +template +void BasicWriter::write_double(T value, const Spec &spec) { // Check type. char type = spec.type(); @@ -3789,7 +3916,8 @@ template template void BasicWriter> class BasicMemoryWriter : public BasicWriter +template> +class BasicMemoryWriter : public BasicWriter { private: internal::MemoryBuffer buffer_; @@ -3850,7 +3978,8 @@ typedef BasicMemoryWriter WMemoryWriter; +--------------+---------------------------+ \endrst */ -template class BasicArrayWriter : public BasicWriter +template +class BasicArrayWriter : public BasicWriter { private: internal::FixedBuffer buffer_; @@ -4120,7 +4249,8 @@ public: // Formats a decimal integer value writing into buffer and returns // a pointer to the end of the formatted string. This function doesn't // write a terminating null character. -template inline void format_decimal(char *&buffer, T value) +template +inline void format_decimal(char *&buffer, T value) { typedef typename internal::IntTraits::MainType MainType; MainType abs_value = static_cast(value); @@ -4156,20 +4286,24 @@ template inline void format_decimal(char *&buffer, T value) \endrst */ -template inline internal::NamedArgWithType arg(StringRef name, const T &arg) +template +inline internal::NamedArgWithType arg(StringRef name, const T &arg) { return internal::NamedArgWithType(name, arg); } -template inline internal::NamedArgWithType arg(WStringRef name, const T &arg) +template +inline internal::NamedArgWithType arg(WStringRef name, const T &arg) { return internal::NamedArgWithType(name, arg); } // The following two functions are deleted intentionally to disable // nested named arguments as in ``format("{}", arg("a", arg("b", 42)))``. -template void arg(StringRef, const internal::NamedArg &) FMT_DELETED_OR_UNDEFINED; -template void arg(WStringRef, const internal::NamedArg &) FMT_DELETED_OR_UNDEFINED; +template +void arg(StringRef, const internal::NamedArg &) FMT_DELETED_OR_UNDEFINED; +template +void arg(WStringRef, const internal::NamedArg &) FMT_DELETED_OR_UNDEFINED; } // namespace fmt #if FMT_GCC_VERSION @@ -4198,7 +4332,8 @@ template void arg(WStringRef, const internal::NamedArg &) F #if FMT_USE_VARIADIC_TEMPLATES #define FMT_VARIADIC_(Const, Char, ReturnType, func, call, ...) \ - template ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), const Args &... args) Const \ + template \ + ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), const Args &... args) Const \ { \ typedef fmt::internal::ArgArray ArgArray; \ typename ArgArray::Type array{ArgArray::template make>(args)...}; \ @@ -4303,14 +4438,16 @@ FMT_VARIADIC(void, print, std::FILE *, CStringRef) FMT_VARIADIC(void, print_colored, Color, CStringRef) namespace internal { -template inline bool is_name_start(Char c) +template +inline bool is_name_start(Char c) { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '_' == c; } // Parses an unsigned integer advancing s to the end of the parsed input. // This function assumes that the first character of s is a digit. -template unsigned parse_nonnegative_int(const Char *&s) +template +unsigned parse_nonnegative_int(const Char *&s) { assert('0' <= *s && *s <= '9'); unsigned value = 0; @@ -4343,7 +4480,8 @@ inline void require_numeric_argument(const Arg &arg, char spec) } } -template void check_sign(const Char *&s, const Arg &arg) +template +void check_sign(const Char *&s, const Arg &arg) { char sign = static_cast(*s); require_numeric_argument(arg, sign); @@ -4369,7 +4507,8 @@ inline internal::Arg BasicFormatter::get_arg(BasicStringRef arg_ return internal::Arg(); } -template inline internal::Arg BasicFormatter::parse_arg_index(const Char *&s) +template +inline internal::Arg BasicFormatter::parse_arg_index(const Char *&s) { const char *error = FMT_NULL; internal::Arg arg = *s < '0' || *s > '9' ? next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error); @@ -4380,7 +4519,8 @@ template inline internal::Arg BasicFormatter inline internal::Arg BasicFormatter::parse_arg_name(const Char *&s) +template +inline internal::Arg BasicFormatter::parse_arg_name(const Char *&s) { assert(internal::is_name_start(*s)); const Char *start = s; @@ -4590,7 +4730,8 @@ const Char *BasicFormatter::format(const Char *&format_str, return s; } -template void BasicFormatter::format(BasicCStringRef format_str) +template +void BasicFormatter::format(BasicCStringRef format_str) { const Char *s = format_str.c_str(); const Char *start = s; @@ -4614,7 +4755,8 @@ template void BasicFormatter::format(Basic write(writer_, start, s); } -template struct ArgJoin +template +struct ArgJoin { It first; It last; @@ -4628,23 +4770,27 @@ template struct ArgJoin } }; -template ArgJoin join(It first, It last, const BasicCStringRef &sep) +template +ArgJoin join(It first, It last, const BasicCStringRef &sep) { return ArgJoin(first, last, sep); } -template ArgJoin join(It first, It last, const BasicCStringRef &sep) +template +ArgJoin join(It first, It last, const BasicCStringRef &sep) { return ArgJoin(first, last, sep); } #if FMT_HAS_GXX_CXX11 -template auto join(const Range &range, const BasicCStringRef &sep) -> ArgJoin +template +auto join(const Range &range, const BasicCStringRef &sep) -> ArgJoin { return join(std::begin(range), std::end(range), sep); } -template auto join(const Range &range, const BasicCStringRef &sep) -> ArgJoin +template +auto join(const Range &range, const BasicCStringRef &sep) -> ArgJoin { return join(std::begin(range), std::end(range), sep); } @@ -4681,21 +4827,25 @@ void format_arg(fmt::BasicFormatter &f, const Char *&format_ namespace fmt { namespace internal { -template struct UdlFormat +template +struct UdlFormat { const Char *str; - template auto operator()(Args &&... args) const -> decltype(format(str, std::forward(args)...)) + template + auto operator()(Args &&... args) const -> decltype(format(str, std::forward(args)...)) { return format(str, std::forward(args)...); } }; -template struct UdlArg +template +struct UdlArg { const Char *str; - template NamedArgWithType operator=(T &&value) const + template + NamedArgWithType operator=(T &&value) const { return {str, std::forward(value)}; } diff --git a/include/spdlog/fmt/bundled/ostream.h b/include/spdlog/fmt/bundled/ostream.h index 98f9f22a..ffa75ab0 100644 --- a/include/spdlog/fmt/bundled/ostream.h +++ b/include/spdlog/fmt/bundled/ostream.h @@ -17,7 +17,8 @@ namespace fmt { namespace internal { -template class FormatBuf : public std::basic_streambuf +template +class FormatBuf : public std::basic_streambuf { private: typedef typename std::basic_streambuf::int_type int_type; @@ -60,12 +61,14 @@ struct DummyStream : std::ostream DummyStream(); // Suppress a bogus warning in MSVC. // Hide all operator<< overloads from std::ostream. - template typename EnableIf::type operator<<(const T &); + template + typename EnableIf::type operator<<(const T &); }; No &operator<<(std::ostream &, int); -template struct ConvertToIntImpl +template +struct ConvertToIntImpl { // Convert to int only if T doesn't have an overloaded operator<<. enum diff --git a/include/spdlog/fmt/bundled/printf.h b/include/spdlog/fmt/bundled/printf.h index 2102cf24..679e8fc1 100644 --- a/include/spdlog/fmt/bundled/printf.h +++ b/include/spdlog/fmt/bundled/printf.h @@ -20,9 +20,11 @@ namespace internal { // Checks if a value fits in int - used to avoid warnings about comparing // signed and unsigned integers. -template struct IntChecker +template +struct IntChecker { - template static bool fits_in_int(T value) + template + static bool fits_in_int(T value) { unsigned max = std::numeric_limits::max(); return value <= max; @@ -33,9 +35,11 @@ template struct IntChecker } }; -template<> struct IntChecker +template<> +struct IntChecker { - template static bool fits_in_int(T value) + template + static bool fits_in_int(T value) { return value >= std::numeric_limits::min() && value <= std::numeric_limits::max(); } @@ -53,7 +57,8 @@ public: FMT_THROW(FormatError("precision is not integer")); } - template int visit_any_int(T value) + template + int visit_any_int(T value) { if (!IntChecker::is_signed>::fits_in_int(value)) FMT_THROW(FormatError("number is too big")); @@ -65,7 +70,8 @@ public: class IsZeroInt : public ArgVisitor { public: - template bool visit_any_int(T value) + template + bool visit_any_int(T value) { return value == 0; } @@ -90,12 +96,14 @@ public: return 'p'; } - template char visit_any_int(T) + template + char visit_any_int(T) { return 'd'; } - template char visit_any_double(T) + template + char visit_any_double(T) { return 'g'; } @@ -106,7 +114,8 @@ public: } }; -template struct is_same +template +struct is_same { enum { @@ -114,7 +123,8 @@ template struct is_same }; }; -template struct is_same +template +struct is_same { enum { @@ -126,7 +136,8 @@ template struct is_same // if T is an integral type. If T is void, the argument is converted to // corresponding signed or unsigned type depending on the type specifier: // 'd' and 'i' - signed, other - unsigned) -template class ArgConverter : public ArgVisitor, void> +template +class ArgConverter : public ArgVisitor, void> { private: internal::Arg &arg_; @@ -153,7 +164,8 @@ public: visit_any_int(value); } - template void visit_any_int(U value) + template + void visit_any_int(U value) { bool is_signed = type_ == 'd' || type_ == 'i'; if (type_ == 's') @@ -211,7 +223,8 @@ public: { } - template void visit_any_int(T value) + template + void visit_any_int(T value) { arg_.type = internal::Arg::CHAR; arg_.int_value = static_cast(value); @@ -238,7 +251,8 @@ public: FMT_THROW(FormatError("width is not integer")); } - template unsigned visit_any_int(T value) + template + unsigned visit_any_int(T value) { typedef typename internal::IntTraits::MainType UnsignedType; UnsignedType width = static_cast(value); @@ -272,7 +286,8 @@ public: superclass will be called. \endrst */ -template class BasicPrintfArgFormatter : public internal::ArgFormatterBase +template +class BasicPrintfArgFormatter : public internal::ArgFormatterBase { private: void write_null_pointer() @@ -367,7 +382,8 @@ public: }; /** The default printf argument formatter. */ -template class PrintfArgFormatter : public BasicPrintfArgFormatter, Char, FormatSpec> +template +class PrintfArgFormatter : public BasicPrintfArgFormatter, Char, FormatSpec> { public: /** Constructs an argument formatter object. */ @@ -378,7 +394,8 @@ public: }; /** This template formats data and writes the output to a writer. */ -template> class PrintfFormatter : private internal::FormatterBase +template> +class PrintfFormatter : private internal::FormatterBase { private: BasicWriter &writer_; @@ -410,7 +427,8 @@ public: void format(BasicCStringRef format_str); }; -template void PrintfFormatter::parse_flags(FormatSpec &spec, const Char *&s) +template +void PrintfFormatter::parse_flags(FormatSpec &spec, const Char *&s) { for (;;) { @@ -438,7 +456,8 @@ template void PrintfFormatter::parse_flags } } -template internal::Arg PrintfFormatter::get_arg(const Char *s, unsigned arg_index) +template +internal::Arg PrintfFormatter::get_arg(const Char *s, unsigned arg_index) { (void)s; const char *error = FMT_NULL; @@ -448,7 +467,8 @@ template internal::Arg PrintfFormatter::ge return arg; } -template unsigned PrintfFormatter::parse_header(const Char *&s, FormatSpec &spec) +template +unsigned PrintfFormatter::parse_header(const Char *&s, FormatSpec &spec) { unsigned arg_index = std::numeric_limits::max(); Char c = *s; @@ -489,7 +509,8 @@ template unsigned PrintfFormatter::parse_h return arg_index; } -template void PrintfFormatter::format(BasicCStringRef format_str) +template +void PrintfFormatter::format(BasicCStringRef format_str) { const Char *start = format_str.c_str(); const Char *s = start; diff --git a/include/spdlog/fmt/bundled/time.h b/include/spdlog/fmt/bundled/time.h index e5f0d772..1d4210c8 100644 --- a/include/spdlog/fmt/bundled/time.h +++ b/include/spdlog/fmt/bundled/time.h @@ -20,7 +20,8 @@ #endif namespace fmt { -template void format_arg(BasicFormatter &f, const char *&format_str, const std::tm &tm) +template +void format_arg(BasicFormatter &f, const char *&format_str, const std::tm &tm) { if (*format_str == ':') ++format_str; diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 8358cee2..8e52095d 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -27,40 +27,84 @@ public: logger(const std::string &name, sink_ptr single_sink); logger(const std::string &name, sinks_init_list sinks); - template logger(std::string name, const It &begin, const It &end); + template + logger(std::string name, const It &begin, const It &end); virtual ~logger(); logger(const logger &) = delete; logger &operator=(const logger &) = delete; - template void log(level::level_enum lvl, const char *fmt, const Args &... args); - template void log(level::level_enum lvl, const char *msg); - template void trace(const char *fmt, const Arg1 &, const Args &... args); - template void debug(const char *fmt, const Arg1 &, const Args &... args); - template void info(const char *fmt, const Arg1 &, const Args &... args); - template void warn(const char *fmt, const Arg1 &, const Args &... args); - template void error(const char *fmt, const Arg1 &, const Args &... args); - template void critical(const char *fmt, const Arg1 &, const Args &... args); + template + void log(level::level_enum lvl, const char *fmt, const Args &... args); + + template + void log(level::level_enum lvl, const char *msg); + + template + void trace(const char *fmt, const Arg1 &, const Args &... args); + + template + void debug(const char *fmt, const Arg1 &, const Args &... args); + + template + void info(const char *fmt, const Arg1 &, const Args &... args); + + template + void warn(const char *fmt, const Arg1 &, const Args &... args); + + template + void error(const char *fmt, const Arg1 &, const Args &... args); + + template + void critical(const char *fmt, const Arg1 &, const Args &... args); #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template void log(level::level_enum lvl, const wchar_t *msg); - template void log(level::level_enum lvl, const wchar_t *fmt, const Args &... args); - template void trace(const wchar_t *fmt, const Args &... args); - template void debug(const wchar_t *fmt, const Args &... args); - template void info(const wchar_t *fmt, const Args &... args); - template void warn(const wchar_t *fmt, const Args &... args); - template void error(const wchar_t *fmt, const Args &... args); - template void critical(const wchar_t *fmt, const Args &... args); -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT + template + void log(level::level_enum lvl, const wchar_t *msg); - template void log(level::level_enum lvl, const T &); - template void trace(const T &msg); - template void debug(const T &msg); - template void info(const T &msg); - template void warn(const T &msg); - template void error(const T &msg); - template void critical(const T &msg); + template + void log(level::level_enum lvl, const wchar_t *fmt, const Args &... args); + + template + void trace(const wchar_t *fmt, const Args &... args); + + template + void debug(const wchar_t *fmt, const Args &... args); + + template + void info(const wchar_t *fmt, const Args &... args); + + template + void warn(const wchar_t *fmt, const Args &... args); + + template + void error(const wchar_t *fmt, const Args &... args); + + template + void critical(const wchar_t *fmt, const Args &... args); + +#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT + template + void log(level::level_enum lvl, const T &); + + template + void trace(const T &msg); + + template + void debug(const T &msg); + + template + void info(const T &msg); + + template + void warn(const T &msg); + + template + void error(const T &msg); + + template + void critical(const T &msg); bool should_log(level::level_enum msg_level) const; void set_level(level::level_enum log_level); diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index d08eac47..2a5203c3 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -19,7 +19,8 @@ namespace spdlog { namespace sinks { * of the message. * If no color terminal detected, omit the escape codes. */ -template class ansicolor_sink : public base_sink +template +class ansicolor_sink : public base_sink { public: explicit ansicolor_sink(FILE *file) @@ -106,7 +107,8 @@ protected: std::unordered_map colors_; }; -template class ansicolor_stdout_sink : public ansicolor_sink +template +class ansicolor_stdout_sink : public ansicolor_sink { public: ansicolor_stdout_sink() @@ -118,7 +120,8 @@ public: using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; using ansicolor_stdout_sink_st = ansicolor_stdout_sink; -template class ansicolor_stderr_sink : public ansicolor_sink +template +class ansicolor_stderr_sink : public ansicolor_sink { public: ansicolor_stderr_sink() diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index 7c628c18..16035ec9 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -18,7 +18,8 @@ #include namespace spdlog { namespace sinks { -template class base_sink : public sink +template +class base_sink : public sink { public: base_sink() = default; diff --git a/include/spdlog/sinks/dist_sink.h b/include/spdlog/sinks/dist_sink.h index c2c91412..3191783a 100644 --- a/include/spdlog/sinks/dist_sink.h +++ b/include/spdlog/sinks/dist_sink.h @@ -18,7 +18,8 @@ // Distribution sink (mux). Stores a vector of sinks which get called when log is called namespace spdlog { namespace sinks { -template class dist_sink : public base_sink +template +class dist_sink : public base_sink { public: explicit dist_sink() diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 9b3cc9f5..6f8517e8 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -22,7 +22,8 @@ namespace spdlog { namespace sinks { /* * Trivial file sink with single file as target */ -template class simple_file_sink SPDLOG_FINAL : public base_sink +template +class simple_file_sink SPDLOG_FINAL : public base_sink { public: explicit simple_file_sink(const filename_t &filename, bool truncate = false) @@ -60,7 +61,8 @@ using simple_file_sink_st = simple_file_sink; /* * Rotating file sink based on size */ -template class rotating_file_sink SPDLOG_FINAL : public base_sink +template +class rotating_file_sink SPDLOG_FINAL : public base_sink { public: rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files) @@ -185,7 +187,8 @@ struct dateonly_daily_file_name_calculator /* * Rotating file sink based on date. rotates at midnight */ -template class daily_file_sink SPDLOG_FINAL : public base_sink +template +class daily_file_sink SPDLOG_FINAL : public base_sink { public: // create daily file sink which rotates on given time diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index a618886b..fa83a18c 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -19,7 +19,8 @@ namespace spdlog { namespace sinks { /* * MSVC sink (logging using OutputDebugStringA) */ -template class msvc_sink : public base_sink +template +class msvc_sink : public base_sink { public: explicit msvc_sink() {} diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h index 46e90775..c0ae4167 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -12,7 +12,8 @@ namespace spdlog { namespace sinks { -template class null_sink : public base_sink +template +class null_sink : public base_sink { protected: void _sink_it(const details::log_msg &) override {} diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 5c4ec810..7d91a1ee 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -12,7 +12,8 @@ #include namespace spdlog { namespace sinks { -template class ostream_sink : public base_sink +template +class ostream_sink : public base_sink { public: explicit ostream_sink(std::ostream &os, bool force_flush = false) diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index fb3e1bc0..35324370 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -14,7 +14,8 @@ namespace spdlog { namespace sinks { -template class stdout_sink SPDLOG_FINAL : public base_sink +template +class stdout_sink SPDLOG_FINAL : public base_sink { using MyType = stdout_sink; @@ -43,7 +44,8 @@ protected: using stdout_sink_mt = stdout_sink; using stdout_sink_st = stdout_sink; -template class stderr_sink SPDLOG_FINAL : public base_sink +template +class stderr_sink SPDLOG_FINAL : public base_sink { using MyType = stderr_sink; diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index 3f5fdfe6..bc036d44 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -18,7 +18,8 @@ namespace spdlog { namespace sinks { /* * Windows color console sink. Uses WriteConsoleA to write to the console with colors */ -template class wincolor_sink : public base_sink +template +class wincolor_sink : public base_sink { public: const WORD BOLD = FOREGROUND_INTENSITY; @@ -89,7 +90,8 @@ private: // // windows color console to stdout // -template class wincolor_stdout_sink : public wincolor_sink +template +class wincolor_stdout_sink : public wincolor_sink { public: wincolor_stdout_sink() @@ -104,7 +106,8 @@ using wincolor_stdout_sink_st = wincolor_stdout_sink; // // windows color console to stderr // -template class wincolor_stderr_sink : public wincolor_sink +template +class wincolor_stderr_sink : public wincolor_sink { public: wincolor_stderr_sink() diff --git a/include/spdlog/sinks/windebug_sink.h b/include/spdlog/sinks/windebug_sink.h index 0ada9b94..353a7bde 100644 --- a/include/spdlog/sinks/windebug_sink.h +++ b/include/spdlog/sinks/windebug_sink.h @@ -14,7 +14,8 @@ namespace spdlog { namespace sinks { /* * Windows debug sink (logging using OutputDebugStringA, synonym for msvc_sink) */ -template using windebug_sink = msvc_sink; +template +using windebug_sink = msvc_sink; using windebug_sink_mt = msvc_sink_mt; using windebug_sink_st = msvc_sink_st; diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 977cc508..21f5951b 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -81,6 +81,7 @@ std::shared_ptr basic_logger_st(const std::string &logger_name, const fi // std::shared_ptr rotating_logger_mt( const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files); + std::shared_ptr rotating_logger_st( const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files); @@ -122,12 +123,15 @@ std::shared_ptr create(const std::string &logger_name, const sink_ptr &s // Create and register a logger with multiple sinks std::shared_ptr create(const std::string &logger_name, sinks_init_list sinks); -template std::shared_ptr create(const std::string &logger_name, const It &sinks_begin, const It &sinks_end); + +template +std::shared_ptr create(const std::string &logger_name, const It &sinks_begin, const It &sinks_end); // Create and register a logger with templated sink type // Example: // spdlog::create("mylog", "dailylog_filename"); -template std::shared_ptr create(const std::string &logger_name, Args... args); +template +std::shared_ptr create(const std::string &logger_name, Args... args); // Create and register an async logger with a single sink std::shared_ptr create_async(const std::string &logger_name, const sink_ptr &sink, size_t queue_size, @@ -142,6 +146,7 @@ std::shared_ptr create_async(const std::string &logger_name, sinks_init_ const std::function &worker_warmup_cb = nullptr, const std::chrono::milliseconds &flush_interval_ms = std::chrono::milliseconds::zero(), const std::function &worker_teardown_cb = nullptr); + template std::shared_ptr create_async(const std::string &logger_name, const It &sinks_begin, const It &sinks_end, size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index fa605e3d..73ef926b 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -1,6 +1,7 @@ #include "includes.h" -template std::string log_info(const T &what, spdlog::level::level_enum logger_level = spdlog::level::info) +template +std::string log_info(const T &what, spdlog::level::level_enum logger_level = spdlog::level::info) { std::ostringstream oss;