From 2a59c1b43f0818e0f8e8ab4d11d9046426148338 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 10 Nov 2022 11:40:30 +0100 Subject: editor, main: add fmtlib dependency snprintf in imgui code is slow. --- compat/format.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 compat/format.hpp (limited to 'compat') diff --git a/compat/format.hpp b/compat/format.hpp new file mode 100644 index 00000000..e126e77b --- /dev/null +++ b/compat/format.hpp @@ -0,0 +1,20 @@ +#pragma once +#include +#include + +namespace floormat { + +using namespace fmt::literals; + +template +std::size_t snformat(char(&buf)[N], Fmt&& fmt, Xs&&... args) +{ + constexpr std::size_t n = N > 0 ? N - 1 : 0; + auto result = fmt::format_to_n(buf, n, std::forward(fmt), std::forward(args)...); + const auto len = std::min(n, result.size); + if constexpr(N > 0) + buf[len] = '\0'; + return len; +} + +} // namespace floormat -- cgit v1.2.3