initial commit

This commit is contained in:
2024-01-01 15:31:33 +01:00
commit 572fdbb5cc
6 changed files with 289 additions and 0 deletions

18
include/Format.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include <string>
#include <memory>
#include <stdexcept>
template <typename... Args>
std::string Format(const std::string &format, Args... args)
{
int size = snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
if (size <= 0)
{
throw std::runtime_error("Error during formatting.");
}
std::unique_ptr<char[]> buf(new char[size]);
snprintf(buf.get(), static_cast<std::size_t>(size), format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}