carb::extras::withFormatNV

Defined in carb/extras/StringSafe.h

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

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

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 and its size. The type should be void(const char*, size_t); any return type will be ignored. The size given will not include the NUL terminator.

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.