Skip to content

Commit

Permalink
Make format_specs not depend on code unit type
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 17, 2024
1 parent 090ee13 commit 8510838
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 122 deletions.
9 changes: 4 additions & 5 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,7 @@ using unsigned_char = typename conditional_t<std::is_integral<Char>::value,
std::make_unsigned<Char>,
type_identity<unsigned>>::type;

// Character (code unit) type is erased to prevent template bloat.
struct fill_t {
private:
enum { max_size = 4 };
Expand Down Expand Up @@ -2106,7 +2107,7 @@ enum class presentation_type : unsigned char {
};

// Format specifiers for built-in and string types.
template <typename Char = char> struct format_specs {
struct format_specs {
int width;
int precision;
presentation_type type;
Expand Down Expand Up @@ -2160,8 +2161,7 @@ template <typename Char> struct arg_ref {
// Format specifiers with width and precision resolved at formatting rather
// than parsing time to allow reusing the same parsed specifiers with
// different sets of arguments (precompilation of format strings).
template <typename Char = char>
struct dynamic_format_specs : format_specs<Char> {
template <typename Char = char> struct dynamic_format_specs : format_specs {
arg_ref<Char> width_ref;
arg_ref<Char> precision_ref;
};
Expand Down Expand Up @@ -2636,8 +2636,7 @@ FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
}

// Checks char specs and returns true iff the presentation type is char-like.
template <typename Char>
FMT_CONSTEXPR auto check_char_specs(const format_specs<Char>& specs) -> bool {
FMT_CONSTEXPR inline auto check_char_specs(const format_specs& specs) -> bool {
if (specs.type != presentation_type::none &&
specs.type != presentation_type::chr &&
specs.type != presentation_type::debug) {
Expand Down
6 changes: 3 additions & 3 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ auto format_duration_value(OutputIt out, Rep val, int) -> OutputIt {
template <typename Char, typename Rep, typename OutputIt,
FMT_ENABLE_IF(std::is_floating_point<Rep>::value)>
auto format_duration_value(OutputIt out, Rep val, int precision) -> OutputIt {
auto specs = format_specs<Char>();
auto specs = format_specs();
specs.precision = precision;
specs.type =
precision >= 0 ? presentation_type::fixed : presentation_type::general;
Expand Down Expand Up @@ -2076,7 +2076,7 @@ template <typename Char> struct formatter<weekday, Char> {
template <typename Rep, typename Period, typename Char>
struct formatter<std::chrono::duration<Rep, Period>, Char> {
private:
format_specs<Char> specs_;
format_specs specs_;
detail::arg_ref<Char> width_ref_;
detail::arg_ref<Char> precision_ref_;
bool localized_ = false;
Expand Down Expand Up @@ -2218,7 +2218,7 @@ struct formatter<std::chrono::time_point<std::chrono::utc_clock, Duration>,

template <typename Char> struct formatter<std::tm, Char> {
private:
format_specs<Char> specs_;
format_specs specs_;
detail::arg_ref<Char> width_ref_;

protected:
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ template <typename Char> FMT_FUNC Char decimal_point_impl(locale_ref) {
#endif

FMT_FUNC auto write_loc(appender out, loc_value value,
const format_specs<>& specs, locale_ref loc) -> bool {
const format_specs& specs, locale_ref loc) -> bool {
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
auto locale = loc.get<std::locale>();
// We cannot use the num_put<char> facet because it may produce output in
Expand Down Expand Up @@ -138,7 +138,7 @@ template <typename Locale> format_facet<Locale>::format_facet(Locale& loc) {

template <>
FMT_API FMT_FUNC auto format_facet<std::locale>::do_put(
appender out, loc_value val, const format_specs<>& specs) const -> bool {
appender out, loc_value val, const format_specs& specs) const -> bool {
return val.visit(
detail::loc_writer<>{out, specs, separator_, grouping_, decimal_point_});
}
Expand Down
Loading

0 comments on commit 8510838

Please sign in to comment.