Cleanup format.h

This commit is contained in:
Victor Zverovich
2024-09-20 19:00:23 -07:00
parent fe79932c26
commit c283b458a5

View File

@ -67,6 +67,10 @@
# include <string_view> # include <string_view>
# define FMT_USE_STRING_VIEW # define FMT_USE_STRING_VIEW
# endif # endif
# if FMT_MSC_VERSION
# include <intrin.h> // _BitScanReverse[64], _BitScanForward[64], _umul128
# endif
#endif // FMT_MODULE #endif // FMT_MODULE
#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS) #if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
@ -119,7 +123,7 @@ template <> struct iterator_traits<fmt::appender> {
using iterator_category = output_iterator_tag; using iterator_category = output_iterator_tag;
using value_type = char; using value_type = char;
using reference = char&; using reference = char&;
using difference_type = ptrdiff_t; using difference_type = fmt::appender::difference_type;
}; };
} // namespace std } // namespace std
@ -168,7 +172,7 @@ FMT_END_NAMESPACE
# define FMT_REDUCE_INT_INSTANTIATIONS 0 # define FMT_REDUCE_INT_INSTANTIATIONS 0
#endif #endif
// __builtin_clz is broken in clang with Microsoft CodeGen: // __builtin_clz is broken in clang with Microsoft codegen:
// https://github.com/fmtlib/fmt/issues/519. // https://github.com/fmtlib/fmt/issues/519.
#if !FMT_MSC_VERSION #if !FMT_MSC_VERSION
# if FMT_HAS_BUILTIN(__builtin_clz) || FMT_GCC_VERSION || FMT_ICC_VERSION # if FMT_HAS_BUILTIN(__builtin_clz) || FMT_GCC_VERSION || FMT_ICC_VERSION
@ -192,10 +196,6 @@ FMT_END_NAMESPACE
# endif # endif
#endif #endif
#if FMT_MSC_VERSION && !defined(FMT_MODULE)
# include <intrin.h> // _BitScanReverse[64], _BitScanForward[64], _umul128
#endif
// Some compilers masquerade as both MSVC and GCC-likes or otherwise support // Some compilers masquerade as both MSVC and GCC-likes or otherwise support
// __builtin_clz and __builtin_clzll, so only define FMT_BUILTIN_CLZ using the // __builtin_clz and __builtin_clzll, so only define FMT_BUILTIN_CLZ using the
// MSVC intrinsics if the clz and clzll builtins are not available. // MSVC intrinsics if the clz and clzll builtins are not available.
@ -2287,8 +2287,7 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
}); });
} }
template <typename Char, typename OutputIt> template <typename Char, typename OutputIt>
FMT_CONSTEXPR auto write(OutputIt out, FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
basic_string_view<type_identity_t<Char>> s,
const format_specs& specs, locale_ref) -> OutputIt { const format_specs& specs, locale_ref) -> OutputIt {
return write<Char>(out, s, specs); return write<Char>(out, s, specs);
} }
@ -3888,6 +3887,11 @@ template <int N, typename Char>
struct formatter<detail::ubitint<N>, Char> struct formatter<detail::ubitint<N>, Char>
: formatter<unsigned long long, Char> {}; : formatter<unsigned long long, Char> {};
template <typename Char>
struct formatter<detail::float128, Char>
: detail::native_formatter<detail::float128, Char,
detail::type::float_type> {};
/** /**
* Converts `p` to `const void*` for pointer formatting. * Converts `p` to `const void*` for pointer formatting.
* *
@ -3932,13 +3936,10 @@ template <> struct formatter<std::byte> : formatter<unsigned> {
}; };
#endif #endif
class bytes { struct bytes {
private: string_view data;
string_view data_;
friend struct formatter<bytes>;
public: explicit bytes(string_view s) : data(s) {}
explicit bytes(string_view data) : data_(data) {}
}; };
template <> struct formatter<bytes> { template <> struct formatter<bytes> {
@ -3958,7 +3959,7 @@ template <> struct formatter<bytes> {
specs.width_ref, ctx); specs.width_ref, ctx);
detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision, detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision,
specs.precision_ref, ctx); specs.precision_ref, ctx);
return detail::write_bytes<char>(ctx.out(), b.data_, specs); return detail::write_bytes<char>(ctx.out(), b.data, specs);
} }
}; };
@ -4066,11 +4067,6 @@ template <typename T, typename Char = char> struct nested_formatter {
} }
}; };
template <typename Char>
struct formatter<detail::float128, Char>
: detail::native_formatter<detail::float128, Char,
detail::type::float_type> {};
inline namespace literals { inline namespace literals {
#if FMT_USE_NONTYPE_TEMPLATE_ARGS #if FMT_USE_NONTYPE_TEMPLATE_ARGS
template <detail_exported::fixed_string Str> constexpr auto operator""_a() { template <detail_exported::fixed_string Str> constexpr auto operator""_a() {