Skip to content

Commit

Permalink
Update bundled fmt to 11.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Feb 28, 2025
1 parent 73c463d commit c78bd3a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
23 changes: 12 additions & 11 deletions include/quill/bundled/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#endif

// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMTQUILL_VERSION 110103
#define FMTQUILL_VERSION 110104

// Detect compiler versions.
#if defined(__clang__) && !defined(__ibmxl__)
Expand Down Expand Up @@ -298,8 +298,8 @@
#endif

#define FMTQUILL_APPLY_VARIADIC(expr) \
using ignore = int[]; \
(void)ignore { 0, (expr, 0)... }
using unused = int[]; \
(void)unused { 0, (expr, 0)... }

// Enable minimal optimizations for more compact code in debug mode.
FMTQUILL_PRAGMA_GCC(push_options)
Expand Down Expand Up @@ -541,7 +541,7 @@ template <typename Char> class basic_string_view {
FMTQUILL_ALWAYS_INLINE
#endif
FMTQUILL_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) {
#if FMTQUILL_HAS_BUILTIN(__buitin_strlen) || FMTQUILL_GCC_VERSION || FMTQUILL_CLANG_VERSION
#if FMTQUILL_HAS_BUILTIN(__builtin_strlen) || FMTQUILL_GCC_VERSION || FMTQUILL_CLANG_VERSION
if (std::is_same<Char, char>::value) {
size_ = __builtin_strlen(detail::narrow(s));
return;
Expand Down Expand Up @@ -744,7 +744,7 @@ class basic_specs {
};

unsigned data_ = 1 << fill_size_shift;
static_assert(sizeof(data_) * CHAR_BIT >= 18, "");
static_assert(sizeof(basic_specs::data_) * CHAR_BIT >= 18, "");

// Character (code unit) type is erased to prevent template bloat.
char fill_data_[max_fill_size] = {' '};
Expand Down Expand Up @@ -2280,15 +2280,15 @@ template <> struct is_output_iterator<appender, char> : std::true_type {};
template <typename It, typename T>
struct is_output_iterator<
It, T,
void_t<decltype(*std::declval<decay_t<It>&>()++ = std::declval<T>())>>
: std::true_type {};
enable_if_t<std::is_assignable<decltype(*std::declval<decay_t<It>&>()++),
T>::value>> : std::true_type {};

#ifndef FMTQUILL_USE_LOCALE
# define FMTQUILL_USE_LOCALE (FMTQUILL_OPTIMIZE_SIZE <= 1)
#endif

// A type-erased reference to an std::locale to avoid a heavy <locale> include.
struct locale_ref {
class locale_ref {
#if FMTQUILL_USE_LOCALE
private:
const void* locale_; // A type-erased pointer to std::locale.
Expand All @@ -2300,6 +2300,7 @@ struct locale_ref {
inline explicit operator bool() const noexcept { return locale_ != nullptr; }
#endif // FMTQUILL_USE_LOCALE

public:
template <typename Locale> auto get() const -> Locale;
};

Expand Down Expand Up @@ -2746,9 +2747,9 @@ template <typename... T> struct fstring {
std::is_same<typename S::char_type, char>::value)>
FMTQUILL_ALWAYS_INLINE fstring(const S&) : str(S()) {
FMTQUILL_CONSTEXPR auto sv = string_view(S());
FMTQUILL_CONSTEXPR int ignore =
FMTQUILL_CONSTEXPR int unused =
(parse_format_string(sv, checker(sv, arg_pack())), 0);
detail::ignore_unused(ignore);
detail::ignore_unused(unused);
}
fstring(runtime_format_string<> fmt) : str(fmt.str) {}

Expand Down Expand Up @@ -2972,5 +2973,5 @@ FMTQUILL_PRAGMA_CLANG(diagnostic pop)
FMTQUILL_PRAGMA_GCC(pop_options)
FMTQUILL_END_NAMESPACE

#include "format.h"

#endif // FMTQUILL_BASE_H_
32 changes: 10 additions & 22 deletions include/quill/bundled/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ FMTQUILL_BEGIN_NAMESPACE
// A compile-time string which is compiled into fast formatting code.
FMTQUILL_EXPORT class compiled_string {};

namespace detail {

template <typename S>
struct is_compiled_string : std::is_base_of<compiled_string, S> {};

namespace detail {

/**
* Converts a string literal `s` into a format string that will be parsed at
* compile time and converted into efficient formatting code. Requires C++17
Expand All @@ -41,16 +41,6 @@ struct is_compiled_string : std::is_base_of<compiled_string, S> {};
# define FMTQUILL_COMPILE(s) FMTQUILL_STRING(s)
#endif

#if FMTQUILL_USE_NONTYPE_TEMPLATE_ARGS
template <typename Char, size_t N, fmtquill::detail::fixed_string<Char, N> Str>
struct udl_compiled_string : compiled_string {
using char_type = Char;
constexpr explicit operator basic_string_view<char_type>() const {
return {Str.data, N - 1};
}
};
#endif

template <typename T, typename... Tail>
auto first(const T& value, const Tail&...) -> const T& {
return value;
Expand Down Expand Up @@ -425,7 +415,7 @@ constexpr auto compile_format_string(S fmt) {
}

template <typename... Args, typename S,
FMTQUILL_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMTQUILL_ENABLE_IF(is_compiled_string<S>::value)>
constexpr auto compile(S fmt) {
constexpr auto str = basic_string_view<typename S::char_type>(fmt);
if constexpr (str.size() == 0) {
Expand Down Expand Up @@ -461,7 +451,7 @@ constexpr FMTQUILL_INLINE OutputIt format_to(OutputIt out, const CompiledFormat&
}

template <typename S, typename... Args,
FMTQUILL_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMTQUILL_ENABLE_IF(is_compiled_string<S>::value)>
FMTQUILL_INLINE std::basic_string<typename S::char_type> format(const S&,
Args&&... args) {
if constexpr (std::is_same<typename S::char_type, char>::value) {
Expand All @@ -488,7 +478,7 @@ FMTQUILL_INLINE std::basic_string<typename S::char_type> format(const S&,
}

template <typename OutputIt, typename S, typename... Args,
FMTQUILL_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMTQUILL_ENABLE_IF(is_compiled_string<S>::value)>
FMTQUILL_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
constexpr auto compiled = detail::compile<Args...>(S());
if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>,
Expand All @@ -503,7 +493,7 @@ FMTQUILL_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
#endif

template <typename OutputIt, typename S, typename... Args,
FMTQUILL_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMTQUILL_ENABLE_IF(is_compiled_string<S>::value)>
auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args)
-> format_to_n_result<OutputIt> {
using traits = detail::fixed_buffer_traits;
Expand All @@ -513,7 +503,7 @@ auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args)
}

template <typename S, typename... Args,
FMTQUILL_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMTQUILL_ENABLE_IF(is_compiled_string<S>::value)>
FMTQUILL_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
-> size_t {
auto buf = detail::counting_buffer<>();
Expand All @@ -522,25 +512,23 @@ FMTQUILL_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
}

template <typename S, typename... Args,
FMTQUILL_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMTQUILL_ENABLE_IF(is_compiled_string<S>::value)>
void print(std::FILE* f, const S& fmt, const Args&... args) {
auto buf = memory_buffer();
fmtquill::format_to(appender(buf), fmt, args...);
detail::print(f, {buf.data(), buf.size()});
}

template <typename S, typename... Args,
FMTQUILL_ENABLE_IF(detail::is_compiled_string<S>::value)>
FMTQUILL_ENABLE_IF(is_compiled_string<S>::value)>
void print(const S& fmt, const Args&... args) {
print(stdout, fmt, args...);
}

#if FMTQUILL_USE_NONTYPE_TEMPLATE_ARGS
inline namespace literals {
template <detail::fixed_string Str> constexpr auto operator""_cf() {
using char_t = remove_cvref_t<decltype(Str.data[0])>;
return detail::udl_compiled_string<char_t, sizeof(Str.data) / sizeof(char_t),
Str>();
return FMTQUILL_COMPILE(Str.data);
}
} // namespace literals
#endif
Expand Down
26 changes: 18 additions & 8 deletions include/quill/bundled/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@ template <typename Char, typename OutputIt, typename DecimalFP,
typename Grouping = digit_grouping<Char>>
FMTQUILL_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
const format_specs& specs, sign s,
locale_ref loc) -> OutputIt {
int exp_upper, locale_ref loc) -> OutputIt {
auto significand = f.significand;
int significand_size = get_significand_size(f);
const Char zero = static_cast<Char>('0');
Expand All @@ -2360,7 +2360,7 @@ FMTQUILL_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
if (specs.type() == presentation_type::fixed) return false;
// Use the fixed notation if the exponent is in [exp_lower, exp_upper),
// e.g. 0.0001 instead of 1e-04. Otherwise use the exponent notation.
const int exp_lower = -4, exp_upper = 16;
const int exp_lower = -4;
return output_exp < exp_lower ||
output_exp >= (specs.precision > 0 ? specs.precision : exp_upper);
};
Expand Down Expand Up @@ -2463,12 +2463,13 @@ template <typename Char> class fallback_digit_grouping {
template <typename Char, typename OutputIt, typename DecimalFP>
FMTQUILL_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f,
const format_specs& specs, sign s,
locale_ref loc) -> OutputIt {
int exp_upper, locale_ref loc) -> OutputIt {
if (is_constant_evaluated()) {
return do_write_float<Char, OutputIt, DecimalFP,
fallback_digit_grouping<Char>>(out, f, specs, s, loc);
fallback_digit_grouping<Char>>(out, f, specs, s,
exp_upper, loc);
} else {
return do_write_float<Char>(out, f, specs, s, loc);
return do_write_float<Char>(out, f, specs, s, exp_upper, loc);
}
}

Expand Down Expand Up @@ -3300,6 +3301,14 @@ FMTQUILL_CONSTEXPR20 auto format_float(Float value, int precision,
return exp;
}

// Numbers with exponents greater or equal to the returned value will use
// the exponential notation.
template <typename T> constexpr auto exp_upper() -> int {
return std::numeric_limits<T>::digits10 != 0
? min_of(16, std::numeric_limits<T>::digits10 + 1)
: 16;
}

template <typename Char, typename OutputIt, typename T>
FMTQUILL_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
locale_ref loc) -> OutputIt {
Expand All @@ -3315,6 +3324,7 @@ FMTQUILL_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
if (specs.width != 0) --specs.width;
}

constexpr int exp_upper = detail::exp_upper<T>();
int precision = specs.precision;
if (precision < 0) {
if (specs.type() != presentation_type::none) {
Expand All @@ -3323,7 +3333,7 @@ FMTQUILL_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
// Use Dragonbox for the shortest format.
using floaty = conditional_t<sizeof(T) >= sizeof(double), double, float>;
auto dec = dragonbox::to_decimal(static_cast<floaty>(value));
return write_float<Char>(out, dec, specs, s, loc);
return write_float<Char>(out, dec, specs, s, exp_upper, loc);
}
}

Expand Down Expand Up @@ -3351,7 +3361,7 @@ FMTQUILL_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,

specs.precision = precision;
auto f = big_decimal_fp{buffer.data(), static_cast<int>(buffer.size()), exp};
return write_float<Char>(out, f, specs, s, loc);
return write_float<Char>(out, f, specs, s, exp_upper, loc);
}

template <typename Char, typename OutputIt, typename T,
Expand All @@ -3378,7 +3388,7 @@ FMTQUILL_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt {
return write_nonfinite<Char>(out, std::isnan(value), specs, s);

auto dec = dragonbox::to_decimal(static_cast<floaty>(value));
return write_float<Char>(out, dec, specs, s, {});
return write_float<Char>(out, dec, specs, s, exp_upper<T>(), {});
}

template <typename Char, typename OutputIt, typename T,
Expand Down

0 comments on commit c78bd3a

Please sign in to comment.