Skip to content

Commit

Permalink
优化str_format函数代码
Browse files Browse the repository at this point in the history
没必要兼容c++20,毕竟format不同,c++20以上自己使用std::vformat或者std::format (#184)
  • Loading branch information
alexliyu7352 authored Oct 9, 2023
1 parent a883b5e commit 273592b
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/Util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ bool end_with(const std::string &str, const std::string &substr);
//拼接格式字符串
template<typename... Args>
std::string str_format(const std::string &format, Args... args) {
#if __cplusplus > 202002L
return std::format(format, args...);
#else

// Calculate the buffer size
auto size_buf = snprintf(nullptr, 0, format.c_str(), args ...) + 1;
// Allocate the buffer
Expand All @@ -244,7 +242,6 @@ std::string str_format(const std::string &format, Args... args) {
auto result = snprintf(buf.get(), size_buf, format.c_str(), args ...);
// Return the formatted string
return std::string(buf.get(), buf.get() + result);
#endif
}

#ifndef bzero
Expand Down

0 comments on commit 273592b

Please sign in to comment.