diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-10 11:40:30 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-10 11:40:30 +0100 |
commit | 2a59c1b43f0818e0f8e8ab4d11d9046426148338 (patch) | |
tree | 9da59a0c707852917c14b64bd519ceb236fb2e45 /compat | |
parent | 86c1bc8b9b5d8ad5fbfef85f34658c1da73baa1f (diff) |
editor, main: add fmtlib dependency
snprintf in imgui code is slow.
Diffstat (limited to 'compat')
-rw-r--r-- | compat/format.hpp | 20 |
1 files changed, 20 insertions, 0 deletions
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 <fmt/core.h> +#include <fmt/compile.h> + +namespace floormat { + +using namespace fmt::literals; + +template<std::size_t N, typename Fmt, typename... Xs> +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>(fmt), std::forward<Xs>(args)...); + const auto len = std::min(n, result.size); + if constexpr(N > 0) + buf[len] = '\0'; + return len; +} + +} // namespace floormat |