From 513734611d2571a581e5f7d96aa527c06453354f Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 25 Sep 2023 16:32:58 -0500 Subject: [PATCH] try fmt::format_string() --- include/LightGBM/utils/common.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/LightGBM/utils/common.h b/include/LightGBM/utils/common.h index 00987740d14f..357a2df8fd89 100644 --- a/include/LightGBM/utils/common.h +++ b/include/LightGBM/utils/common.h @@ -1201,8 +1201,8 @@ inline static std::vector StringToArray(const std::string& str, char delimite * /Users/jlamb/repos/LightGBM/include/LightGBM/utils/common.h:1203:35: error: 'format' is not a constant expression */ template -inline static void format_to_buf(char* buffer, const size_t buf_len, const char* format, const T value) { - const auto result = fmt::format_to_n(buffer, buf_len, format, value); +inline static void format_to_buf(char* buffer, const size_t buf_len, fmt::format_string format, const T value) { + auto result = fmt::format_to_n(buffer, buf_len, format, value); if (result.size >= buf_len) { Log::Fatal("Numerical conversion failed. Buffer is too small."); } @@ -1212,21 +1212,21 @@ inline static void format_to_buf(char* buffer, const size_t buf_len, const char* template struct __TToStringHelper { void operator()(T value, char* buffer, size_t buf_len) const { - format_to_buf(buffer, buf_len, "{}", value); + format_to_buf(buffer, buf_len, fmt::format_string("{}"), value); } }; template struct __TToStringHelper { void operator()(T value, char* buffer, size_t buf_len) const { - format_to_buf(buffer, buf_len, "{:g}", value); + format_to_buf(buffer, buf_len, fmt::format_string("{:g}"), value); } }; template struct __TToStringHelper { void operator()(T value, char* buffer, size_t buf_len) const { - format_to_buf(buffer, buf_len, "{:.17g}", value); + format_to_buf(buffer, buf_len, fmt::format_string("{:.17g}"), value); } }; @@ -1234,7 +1234,7 @@ struct __TToStringHelper { * Converts an array to a string with with values separated by the space character. * This method replaces Common's ``ArrayToString`` and ``ArrayToStringFast`` functionality * and is locale-independent. -* +* * \note If ``high_precision_output`` is set to true, * floating point values are output with more digits of precision. */