use constexpr
This commit is contained in:
parent
969dcce51a
commit
45c7c29bd5
@ -764,18 +764,15 @@ inline std::chrono::duration<Rep, std::milli> get_milliseconds(
|
|||||||
|
|
||||||
template <typename Char, typename Rep, typename OutputIt>
|
template <typename Char, typename Rep, typename OutputIt>
|
||||||
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
|
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
|
||||||
using context = FMT_BUFFER_CONTEXT(type_identity_t<Char>);
|
static constexpr const Char pr_f[] = {'{', ':', '.', '{', '}', 'f', '}', 0};
|
||||||
|
if (precision >= 0) return format_to(out, FMT_STRING(pr_f), val, precision);
|
||||||
const Char pr_f[] = {'{', ':', '.', '{', '}', 'f', '}', 0};
|
static constexpr const Char fp_f[] = {'{', ':', 'g', '}', 0};
|
||||||
if (precision >= 0) {
|
static constexpr const Char format[] = {'{', '}', 0};
|
||||||
return vformat_to(out, to_string_view(pr_f),
|
if(std::is_floating_point<Rep>::value) {
|
||||||
make_format_args<context>(val, precision));
|
return format_to(out, FMT_STRING(fp_f), val);
|
||||||
|
} else {
|
||||||
|
return format_to(out, FMT_STRING(format), val);
|
||||||
}
|
}
|
||||||
const Char fp_f[] = {'{', ':', 'g', '}', 0};
|
|
||||||
const Char format[] = {'{', '}', 0};
|
|
||||||
return vformat_to(
|
|
||||||
out, to_string_view(std::is_floating_point<Rep>::value ? fp_f : format),
|
|
||||||
make_format_args<context>(val));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename OutputIt>
|
template <typename Char, typename OutputIt>
|
||||||
@ -793,19 +790,12 @@ OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) {
|
|||||||
|
|
||||||
template <typename Char, typename Period, typename OutputIt>
|
template <typename Char, typename Period, typename OutputIt>
|
||||||
OutputIt format_duration_unit(OutputIt out) {
|
OutputIt format_duration_unit(OutputIt out) {
|
||||||
using context = FMT_BUFFER_CONTEXT(type_identity_t<Char>);
|
if (const char* unit = get_units<Period>())
|
||||||
|
|
||||||
if (const char* unit = get_units<Period>()) {
|
|
||||||
return copy_unit(string_view(unit), out, Char());
|
return copy_unit(string_view(unit), out, Char());
|
||||||
}
|
static constexpr const Char num_f[] = {'[', '{', '}', ']', 's', 0};
|
||||||
const Char num_f[] = {'[', '{', '}', ']', 's', 0};
|
if (const_check(Period::den == 1)) return format_to(out, FMT_STRING(num_f), Period::num);
|
||||||
if (const_check(Period::den == 1)) {
|
static constexpr const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};
|
||||||
return vformat_to(out, to_string_view(num_f),
|
return format_to(out, FMT_STRING(num_def_f), Period::num, Period::den);
|
||||||
make_format_args<context>(Period::num));
|
|
||||||
}
|
|
||||||
const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};
|
|
||||||
return vformat_to(out, to_string_view(num_def_f),
|
|
||||||
make_format_args<context>(Period::num, Period::den));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext, typename OutputIt, typename Rep,
|
template <typename FormatContext, typename OutputIt, typename Rep,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user