I have a MFC application, but it is configured to build with the C++ 20 standard. Where useful I try to use the newer constructs.
Today, I decided to try and implement some variadic functions. This is what I have so far:
void CBaseCsvImporter::LogInfo(const CString& msg)
{
m_dlgLog.AddLogEntry(msg, true);
}
void CBaseCsvImporter::LogSkip(const CString& msg)
{
m_dlgLog.AddLogEntry(msg, true);
++m_skippedCount;
}
void CBaseCsvImporter::LogError(const CString& msg)
{
m_dlgLog.AddLogEntry(msg, true);
m_dlgLog.SetErrorMode(true);
++m_errorCount;
}
void CBaseCsvImporter::LogInfo(const wchar_t* fmt, ...)
{
CString msg;
va_list args;
va_start(args, fmt);
msg.FormatV(fmt, args);
va_end(args);
LogInfo(msg); // calls the existing CString overload
}
void CBaseCsvImporter::LogSkip(const wchar_t* fmt, ...)
{
CString msg;
va_list args;
va_start(args, fmt);
msg.FormatV(fmt, args);
va_end(args);
LogSkip(msg);
}
void CBaseCsvImporter::LogError(const wchar_t* fmt, ...)
{
CString msg;
va_list args;
va_start(args, fmt);
msg.FormatV(fmt, args);
va_end(args);
LogError(msg);
}
Understandably the Visual Studio IDE started showing code analysis warnings, discouraging me from using this approach:

I decided to ask Copilot / ChatGPT about this and it prosed using these functions in the header instead:
template<typename... Args>
void LogInfo(std::wstring_view fmt, Args&&... args)
{
std::wstring msg = std::vformat(fmt, std::make_wformat_args(args...));
LogInfo(CString(msg.c_str()));
}
AI says that I would need to adjust my code to call it like this:
LogSkip(L"Skipped line {}: duplicate publisher '{}'", csvLine, name);
Eventually the error messages will come from the string table as a resource. I would appreciate guidance on the best way forward to make use of the new way of doing the variadic functiosn, but keeping in mind that ultimately I use CString.