Fmt: va_list issues

Created on 11 May 2016  路  2Comments  路  Source: fmtlib/fmt

If there is a support function va_list
std::string StrTest(int x, ...) { va_list args; va_start(args, x); std::string s = fmt::format("{0} {1} {0}.", args); va_end(args); return s; }
StrTest(1, "one", 2)

Most helpful comment

Varargs are not supported because they are inherently unsafe, but you can use variadic templates instead:

#include "fmt/format.h"

template <typename... T>
std::string StrTest(int x, const T & ... args) {
  return fmt::format("{0} {1} {0}.", args...);
}

StrTest(1, "one", 2);

All 2 comments

Varargs are not supported because they are inherently unsafe, but you can use variadic templates instead:

#include "fmt/format.h"

template <typename... T>
std::string StrTest(int x, const T & ... args) {
  return fmt::format("{0} {1} {0}.", args...);
}

StrTest(1, "one", 2);

FMT_VARIADIC and fmt::ArgList for pre-C++11

Was this page helpful?
0 / 5 - 0 ratings