carb::extras::withFormatV

Defined in carb/extras/StringSafe.h

template<size_t StackSize = 256, class Callable>
void carb::extras::withFormatV(const char *fmt, va_list ap, Callable &&c)

Formats as with vsnprintf() and calls a Callable with the result.

The memory for the string is managed for the caller.

This function attempts to use the stack first but will fall back to the heap if the given fmt and arguments do not fit on the stack.

Template Parameters
  • StackSize – The size of the stack buffer to reserve. The default is 256 characters. This amount includes the NUL terminator.

  • Callable – The type of callable that will be invoked with the formatted string. The type should be void(const char*); any return type will be ignored.

Parameters
  • fmt – The printf-style format string.

  • ap – The collection of variadic arguments as initialized by va_start or va_copy.

  • c – The Callable that will be invoked after the string format. Any return value is ignored. It is undefined behavior to use the pointer value passed to c after c returns.