blob: e126e77b29823a82b839a61afb240c8508091139 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
|