libs/libvtrutil/src/vtr_util.cpp
//Returns a std::string formatted using a printf-style format string taking
//an explicit va_list
Returns a std::string formatted using a printf-style format string taking
an explicit va_list
Returns a std :: string formatted using a printf - style format string taking an explicit va_list
std::string vstring_fmt(const char* fmt, va_list args) {
    va_list va_args_copy;
    va_copy(va_args_copy, args);
    int len = std::vsnprintf(nullptr, 0, fmt, va_args_copy);
    va_end(va_args_copy); 
    VTR_ASSERT_MSG(len >= 0, "Problem decoding format string");
    size_t buf_size = len + 1; 
    std::unique_ptr<char[]> buf(new char[buf_size]);
    len = std::vsnprintf(buf.get(), buf_size, fmt, args);
    VTR_ASSERT_MSG(len >= 0, "Problem decoding format string");
    VTR_ASSERT(static_cast<size_t>(len) == buf_size - 1);
    return std::string(buf.get(), len);
}
std :: string vstring_fmt ( const char * fmt , va_list args ) { va_list va_args_copy ; va_copy ( va_args_copy , args ) ; int len = std :: vsnprintf ( nullptr , 0 , fmt , va_args_copy ) ; va_end ( va_args_copy ) ; VTR_ASSERT_MSG ( len >= 0 , " " ) ; size_t buf_size = len + 1 ; std :: unique_ptr < char [ ] > buf ( new char [ buf_size ] ) ; len = std :: vsnprintf ( buf . get ( ) , buf_size , fmt , args ) ; VTR_ASSERT_MSG ( len >= 0 , " " ) ; VTR_ASSERT ( static_cast < size_t > ( len ) == buf_size - 1 ) ; return std :: string ( buf . get ( ) , len ) ; }
Returns a std::string formatted using a printf-style format string taking
an explicit va_list
Returns a std :: string formatted using a printf - style format string taking an explicit va_list
// We need to copy the args so we don't change them before the true formating //Determine the formatted length using a copy of the args //Clean-up //Negative if there is a problem with the format string //For terminator //Allocate a buffer //  unique_ptr will free buffer automatically //Format into the buffer using the original args //Build the string from the buffer