Skip to content

Commit ba7a3be

Browse files
authored
Merge pull request #11890 from velconia/fix_ut
Add template specialization of Sprintf
2 parents 8133736 + 0f03cbb commit ba7a3be

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

paddle/fluid/string/printf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ void Fprintf(std::ostream& out, const char* fmt, const Args&... args) {
8383
tinyformat::vformat(out, fmt, tinyformat::makeFormatList(args...));
8484
}
8585

86+
template <typename... Args>
87+
std::string Sprintf(const Args&... args) {
88+
std::ostringstream oss;
89+
Fprintf(oss, "");
90+
return oss.str();
91+
}
92+
8693
template <typename... Args>
8794
std::string Sprintf(const char* fmt, const Args&... args) {
8895
std::ostringstream oss;

paddle/fluid/string/printf_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ TEST(StringPrintf, StringPrintf) {
2727
EXPECT_EQ(std::string("Wednesday, July 27, 14:44"),
2828
paddle::string::Sprintf("%s, %s %d, %.2d:%.2d", weekday, month, day,
2929
hour, min));
30+
EXPECT_EQ(std::string(""), paddle::string::Sprintf());
3031
}

0 commit comments

Comments
 (0)