diff options
Diffstat (limited to 'kms++/inc')
| -rw-r--r-- | kms++/inc/kms++/format.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/kms++/inc/kms++/format.h b/kms++/inc/kms++/format.h new file mode 100644 index 0000000..b48babe --- /dev/null +++ b/kms++/inc/kms++/format.h @@ -0,0 +1,28 @@ +#pragma once + +#include <cstdio> +#include <format> +#include <string> + +// This can be removed when moving to C++23. For now, this gives us +// fmt::format() and fmt::print(). + +namespace fmt { + +using std::format; + +template<typename... Args> +void print(std::format_string<Args...> fmtstr, Args&&... args) +{ + std::string s = std::format(fmtstr, std::forward<Args>(args)...); + std::fwrite(s.data(), 1, s.size(), stdout); +} + +template<typename... Args> +void print(std::FILE* f, std::format_string<Args...> fmtstr, Args&&... args) +{ + std::string s = std::format(fmtstr, std::forward<Args>(args)...); + std::fwrite(s.data(), 1, s.size(), f); +} + +} // namespace fmt |
