Skip to content

Commit

Permalink
mark format methods const
Browse files Browse the repository at this point in the history
  • Loading branch information
arBmind committed Jun 17, 2024
1 parent 7fd7769 commit 6b461f0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/enum19.lib/enum19/Enum.fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
template<enum19::HasMetaEnum T, class Char> struct fmt::formatter<T, Char> {
constexpr auto parse(fmt::basic_format_parse_context<Char>& ctx) { return ctx.begin(); }

template<typename FormatCtx> auto format(const T& v, FormatCtx& ctx) {
template<typename FormatCtx> auto format(const T& v, FormatCtx& ctx) const {
auto underlying = static_cast<std::underlying_type_t<T>>(v);
return fmt::format_to(ctx.out(), "{} ({})", enum19::valueName(v), underlying);
}
Expand Down
2 changes: 1 addition & 1 deletion src/string19.lib/string19/StringView.fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
template<class Char> struct fmt::formatter<string19::StringView, Char> {
constexpr auto parse(fmt::basic_format_parse_context<Char>& ctx) { return ctx.begin(); }

template<typename FormatContext> auto format(const string19::StringView& v, FormatContext& ctx) {
template<typename FormatContext> auto format(const string19::StringView& v, FormatContext& ctx) const {
auto out = ctx.out();
for (auto i = 0u; i < v.count; i++) *out++ = v[i];
return out;
Expand Down
2 changes: 1 addition & 1 deletion src/strong19.lib/strong19/Strong.fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
template<class T, class Char> requires(strong19::is_strong<T>) struct fmt::formatter<T, Char> {
constexpr auto parse(fmt::basic_format_parse_context<Char>& ctx) { return ctx.begin(); }

template<typename FormatContext> auto format(const T& v, FormatContext& ctx) {
template<typename FormatContext> auto format(const T& v, FormatContext& ctx) const {
return fmt::format_to(ctx.out(), "{}{{{}}}", strong19::strong_name<T>, v.v);
}
};
8 changes: 3 additions & 5 deletions src/tuple19.lib/tuple19/Tuple.fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ namespace tuple19 {
template<class... Ts> constexpr auto make_format_args(Tuple<Ts...> const& args) {
return [&]<size_t... Is>(std::index_sequence<Is...> const&) {
return fmt::make_format_args(args.template at<Is>()...);
}
(std::make_index_sequence<sizeof...(Ts)>{});
}(std::make_index_sequence<sizeof...(Ts)>{});
}

} // namespace tuple19

template<class... Ts, class Char> struct fmt::formatter<tuple19::Tuple<Ts...>, Char> {
constexpr auto parse(fmt::basic_format_parse_context<Char>& ctx) { return ctx.begin(); }

template<typename FormatContext> auto format(tuple19::Tuple<Ts...> const& v, FormatContext& ctx) {
template<typename FormatContext> auto format(tuple19::Tuple<Ts...> const& v, FormatContext& ctx) const {
if constexpr (sizeof...(Ts) == 0) {
return fmt::format_to(ctx.out(), "Tuple<>");
}
Expand All @@ -30,8 +29,7 @@ template<class... Ts, class Char> struct fmt::formatter<tuple19::Tuple<Ts...>, C
auto out = fmt::format_to(ctx.out(), "{}", v.template at<0>());
((out = fmt::format_to(out, ", {}", v.template at<Is>())), ...);
return out;
}
(std::make_index_sequence<sizeof...(Ts)>{});
}(std::make_index_sequence<sizeof...(Ts)>{});
}
}
};

0 comments on commit 6b461f0

Please sign in to comment.