Repository: fmtlib/fmt
File: include/fmt/format.h (C/C++)

Code before:

template <typename T>
struct formatter<nested_view<T>> {
  FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
    return ctx.begin();
  }
  auto format(nested_view<T> view, format_context& ctx) const
      -> decltype(ctx.out()) {
    return view.fmt->format(*view.value, ctx);
  }
};

template <typename T>
struct nested_formatter {
 private:
  int width_ = 0;
  detail::fill_t<char> fill_;
  align_t align_ : 4;
  formatter<T> formatter_;

 public:
  // Using initialization list for 'align_' because default member initializers
  // for bit-fields are C++20
  constexpr nested_formatter() noexcept(
      std::is_nothrow_constructible<formatter<T>>::value)
      : align_(align_t::none) {}

  FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
    auto specs = detail::dynamic_format_specs<char>();
    auto it = parse_format_specs(
      ctx.begin(), ctx.end(), specs, ctx, detail::type::none_type);
    width_ = specs.width;
    fill_ = specs.fill;
    align_ = specs.align;
    ctx.advance_to(it);
    return formatter_.parse(ctx);
  }

  template <typename F>
  auto write_padded(format_context& ctx, F write) const -> decltype(ctx.out()) {
    if (width_ == 0) return write(ctx.out());
    auto buf = memory_buffer();
    write(std::back_inserter(buf));
    auto specs = format_specs<>();
    specs.width = width_;
    specs.fill = fill_;
    specs.align = align_;
    return detail::write(ctx.out(), string_view(buf.data(), buf.size()), specs);
  }

  auto nested(const T& value) const -> nested_view<T> {

Review comment (suggestion):
Let's move initialization of `width_` here to keep all member initialization in one place and remove the comment above.

Code after:

template <typename T>
struct formatter<nested_view<T>> {
  FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
    return ctx.begin();
  }
  auto format(nested_view<T> view, format_context& ctx) const
      -> decltype(ctx.out()) {
    return view.fmt->format(*view.value, ctx);
  }
};

template <typename T>
struct nested_formatter {
 private:
  int width_;
  detail::fill_t<char> fill_;
  align_t align_ : 4;
  formatter<T> formatter_;

 public:
  constexpr nested_formatter() : width_(0), align_(align_t::none) {}

  FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
    auto specs = detail::dynamic_format_specs<char>();
    auto it = parse_format_specs(
      ctx.begin(), ctx.end(), specs, ctx, detail::type::none_type);
    width_ = specs.width;
    fill_ = specs.fill;
    align_ = specs.align;
    ctx.advance_to(it);
    return formatter_.parse(ctx);
  }

  template <typename F>
  auto write_padded(format_context& ctx, F write) const -> decltype(ctx.out()) {
    if (width_ == 0) return write(ctx.out());
    auto buf = memory_buffer();
    write(std::back_inserter(buf));
    auto specs = format_specs<>();
    specs.width = width_;
    specs.fill = fill_;
    specs.align = align_;
    return detail::write(ctx.out(), string_view(buf.data(), buf.size()), specs);
  }

  auto nested(const T& value) const -> nested_view<T> {
    return nested_view<T>{&formatter_, &value};
  }
};