10#include "../microfmt.hpp"
34struct is_timespec_like<T, std::void_t<decltype(std::declval<T>().tv_sec), decltype(std::declval<T>().tv_nsec)>>
41template <
typename T,
typename =
void>
struct is_timeval_like : std::false_type {};
49struct is_timeval_like<T, std::void_t<decltype(std::declval<T>().tv_sec), decltype(std::declval<T>().tv_usec)>>
80template <
typename T>
struct formatter<T, std::enable_if_t<is_timespec_v<T>>> {
95 auto spec = ctx.spec();
96 if (!spec.empty() && spec.front() ==
':') {
97 spec.remove_prefix(1);
100 if (c ==
'm' || c ==
'3')
102 else if (c ==
'u' || c ==
'6')
104 else if (c ==
'n' || c ==
'9')
106 else if (c ==
'r' || c ==
'R')
117 RELOCO_BEGIN_UNSAFE_CODE
119 int64_t
sec =
static_cast<int64_t
>(ts.tv_sec);
120 uint32_t nsec =
static_cast<uint32_t
>(ts.tv_nsec);
124 detail::format_unsigned<detail::radix::decimal>(out,
static_cast<uint64_t
>(-
sec),
false, 0);
126 detail::format_unsigned<detail::radix::decimal>(out,
static_cast<uint64_t
>(
sec),
false, 0);
130 if (precision == 3) {
131 detail::format_unsigned<detail::radix::decimal>(out, nsec / 1'000'000,
false, 3);
132 }
else if (precision == 6) {
133 detail::format_unsigned<detail::radix::decimal>(out, nsec / 1'000,
false, 6);
135 detail::format_unsigned<detail::radix::decimal>(out, nsec,
false, 9);
157template <
typename T>
struct formatter<T, std::enable_if_t<is_timeval_v<T>>> {
161 uint8_t precision{6};
165 bool show_unit{
true};
172 auto spec = ctx.spec();
173 if (!spec.empty() && spec.front() ==
':') {
174 spec.remove_prefix(1);
176 for (
char c : spec) {
177 if (c ==
'm' || c ==
'3')
179 else if (c ==
'u' || c ==
'6')
181 else if (c ==
'r' || c ==
'R')
192 RELOCO_BEGIN_UNSAFE_CODE
194 int64_t
sec =
static_cast<int64_t
>(tv.tv_sec);
195 uint32_t usec =
static_cast<uint32_t
>(tv.tv_usec);
199 detail::format_unsigned<detail::radix::decimal>(out,
static_cast<uint64_t
>(-
sec),
false, 0);
201 detail::format_unsigned<detail::radix::decimal>(out,
static_cast<uint64_t
>(
sec),
false, 0);
205 if (precision == 3) {
206 detail::format_unsigned<detail::radix::decimal>(out, usec / 1'000,
false, 3);
208 detail::format_unsigned<detail::radix::decimal>(out, usec,
false, 6);
Definition microfmt.hpp:881
constexpr bool is_timeval_v
Variable template for detail::is_timeval_like.
Definition posix_time.hpp:66
constexpr bool is_timespec_v
Variable template for detail::is_timespec_like.
Definition posix_time.hpp:59
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
RELOCO_END_UNSAFE_CODE
Definition remote_object.hpp:132
SFINAE trait detecting timespec-like types with tv_sec/tv_nsec.
Definition posix_time.hpp:26
SFINAE trait detecting timeval-like types with tv_sec/tv_usec.
Definition posix_time.hpp:41