#ifndef DISTRIBUTION_SERVICE_BASIC_H #define DISTRIBUTION_SERVICE_BASIC_H #include "string" namespace CTL { template struct is_char_ptr { static const bool value = false; }; template<> struct is_char_ptr { static const bool value = true; }; template<> struct is_char_ptr { static const bool value = true; }; template struct decay_type_simple { typedef std::remove_cv_t> type; }; template static typename std::enable_if::type>::value, std::string>::type convert_to_string(T&& value) { return value ? value : "null"; } template static typename std::enable_if::type, bool>::value, std::string>::type convert_to_string(T&& value) { return value ? "true" : "false"; } template static typename std::enable_if::type>::value && !std::is_same::type, bool>::value, std::string>::type convert_to_string(T&& value) { return std::to_string(static_cast(value)); } template static typename std::enable_if::type>::value, std::string>::type convert_to_string(T&& value) { return std::to_string(static_cast(value)); } // 通用版本 template static typename std::enable_if::type>::value && !std::is_same::type, bool>::value && !std::is_integral::type>::value && !std::is_floating_point::type>::value, std::string>::type convert_to_string(T&& value) { std::stringstream ss; ss << value; return ss.str(); } template static void format_one_arg(std::string& result, T&& value) { size_t pos = result.find("{}"); if (pos != std::string::npos) { std::string replacement = convert_to_string(std::forward(value)); result.replace(pos, 2, replacement); } } static std::string format_braces_template(std::string fmt_str) { return fmt_str; } template static std::string format_braces_template(std::string fmt_str, T&& first, Rest&&... rest) { format_one_arg(fmt_str, std::forward(first)); if (sizeof...(rest) > 0) { return format_braces_template(fmt_str, std::forward(rest)...); } return fmt_str; } template static std::string format_braces_template(std::string fmt_str, T&& first) { format_one_arg(fmt_str, std::forward(first)); return fmt_str; } } #endif