diff --git a/include/onnxruntime/core/common/make_string.h b/include/onnxruntime/core/common/make_string.h index c47e6cc35e48..6148ef63e726 100644 --- a/include/onnxruntime/core/common/make_string.h +++ b/include/onnxruntime/core/common/make_string.h @@ -19,36 +19,43 @@ #include #include +#include #include -#include "core/util/force_inline.h" - namespace onnxruntime { namespace detail { -ORT_FORCEINLINE void MakeStringImpl(std::ostringstream& /*ss*/) noexcept { +inline void MakeStringImpl(std::ostringstream& /*ss*/) noexcept { } template -ORT_FORCEINLINE void MakeStringImpl(std::ostringstream& ss, const T& t) noexcept { +inline void MakeStringImpl(std::ostringstream& ss, const T& t) noexcept { ss << t; } template -ORT_FORCEINLINE void MakeStringImpl(std::ostringstream& ss, const T& t, const Args&... args) noexcept { +inline void MakeStringImpl(std::ostringstream& ss, const T& t, const Args&... args) noexcept { MakeStringImpl(ss, t); MakeStringImpl(ss, args...); } // see MakeString comments for explanation of why this is necessary template -ORT_FORCEINLINE std::string MakeStringImpl(const Args&... args) noexcept { +inline std::string MakeStringImpl(const Args&... args) noexcept { std::ostringstream ss; MakeStringImpl(ss, args...); return ss.str(); } +template +inline std::string MakeStringWithClassicLocaleImpl(const Args&... args) noexcept { + std::ostringstream ss; + ss.imbue(std::locale::classic()); + MakeStringImpl(ss, args...); + return ss.str(); +} + // // Infrastructure to convert char[n] to char* to reduce binary size // @@ -80,7 +87,7 @@ using if_char_array_make_ptr_t = typename if_char_array_make_ptr::type; * This version uses the current locale. */ template -ORT_FORCEINLINE std::string MakeString(const Args&... args) { +inline std::string MakeString(const Args&... args) { // We need to update the types from the MakeString template instantiation to decay any char[n] to char*. // e.g. MakeString("in", "out") goes from MakeString to MakeStringImpl // so that MakeString("out", "in") will also match MakeStringImpl instead of requiring @@ -100,28 +107,25 @@ ORT_FORCEINLINE std::string MakeString(const Args&... args) { * This version uses std::locale::classic(). */ template -ORT_FORCEINLINE std::string MakeStringWithClassicLocale(const Args&... args) { - std::ostringstream ss; - ss.imbue(std::locale::classic()); - detail::MakeStringImpl(ss, args...); - return ss.str(); +inline std::string MakeStringWithClassicLocale(const Args&... args) { + return detail::MakeStringWithClassicLocaleImpl(detail::if_char_array_make_ptr_t(args)...); } // MakeString versions for already-a-string types. -ORT_FORCEINLINE std::string MakeString(const std::string& str) { +inline std::string MakeString(const std::string& str) { return str; } -ORT_FORCEINLINE std::string MakeString(const char* cstr) { +inline std::string MakeString(const char* cstr) { return cstr; } -ORT_FORCEINLINE std::string MakeStringWithClassicLocale(const std::string& str) { +inline std::string MakeStringWithClassicLocale(const std::string& str) { return str; } -ORT_FORCEINLINE std::string MakeStringWithClassicLocale(const char* cstr) { +inline std::string MakeStringWithClassicLocale(const char* cstr) { return cstr; }