27 template <std::size_t N,
typename... Args>
28 int Sprintf(
char (&
buf)[N],
const char* fmt, Args&&... args) {
29 if constexpr (
sizeof...(Args) == 0) {
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wformat-security"
33 auto i = std::snprintf(
buf, N, fmt);
34 #pragma GCC diagnostic pop
37 return std::snprintf(
buf, N, fmt, std::forward<Args>(args)...);
44 template <std::size_t N,
typename... Args>
46 int sz =
Sprintf(
buf, fmt, std::forward<Args>(args)...);
48 if (sz < 0 || std::size_t(sz) >= N) {
49 throw std::runtime_error(
"SprintfAsrt buffer too small or snprintf error");
52 assert(sz >= 0 && std::size_t(sz) < N);
In mechanism libraries, cannot use auto const token = nrn_ensure_model_data_are_sorted(); because the...
void SprintfAsrt(char(&buf)[N], const char *fmt, Args &&... args)
assert if the Sprintf format data does not fit into buf
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Type-safe sprintf replacement using snprintf with automatic buffer size deduction.