Skip to content

Commit 12d9498

Browse files
committed
update utils string_format to const char* and use std::forward for arguments
1 parent 7332cc2 commit 12d9498

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

include/Utils.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,13 @@ inline std::vector<T> get_triangle_strip_outline_indices(const std::size_t num_v
277277
}
278278

279279
template<class... Args>
280-
std::string string_format(std::string_view fmt, const Args&... args)
280+
std::string string_format(const char* fmt, Args&&... args)
281281
{
282-
const int n = std::snprintf(nullptr, 0, fmt.data(), args...);
282+
const int n = std::snprintf(nullptr, 0, fmt, std::forward<Args>(args)...);
283283
if (n < 0)
284284
throw std::runtime_error("formatting failed");
285-
std::string out;
286-
out.resize(static_cast<size_t>(n));
287-
std::snprintf(out.data(), out.size() + 1, fmt.data(), args...);
285+
std::string out(static_cast<size_t>(n), '\0'); // since c++11: str[str.size()] is '\0'
286+
std::snprintf(&out[0], out.size() + 1, fmt, std::forward<Args>(args)...);
288287
return out;
289288
}
290289

0 commit comments

Comments
 (0)