Fix constness
This commit is contained in:
+4
-2
@@ -12,6 +12,7 @@
|
||||
#include <stdio.h> // FILE
|
||||
#include <string.h> // strlen
|
||||
|
||||
// <cstddef> is also included transitively from <type_traits>.
|
||||
#include <cstddef> // std::byte
|
||||
#include <type_traits> // std::enable_if
|
||||
|
||||
@@ -1332,8 +1333,9 @@ template <typename Context> class value {
|
||||
parse_ctx.advance_to(f.parse(parse_ctx));
|
||||
using qualified_type =
|
||||
conditional_t<has_const_formatter<T, Context>(), const T, T>;
|
||||
// Calling format through a mutable reference is deprecated.
|
||||
ctx.advance_to(f.format(*static_cast<qualified_type*>(arg), ctx));
|
||||
// format must be const for compatibility with std::format and compilation.
|
||||
const auto& cf = f;
|
||||
ctx.advance_to(cf.format(*static_cast<qualified_type*>(arg), ctx));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+14
-12
@@ -4121,12 +4121,13 @@ template <> struct formatter<bytes> {
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(bytes b, FormatContext& ctx) -> decltype(ctx.out()) {
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs_.width,
|
||||
specs_.width_ref, ctx);
|
||||
auto format(bytes b, FormatContext& ctx) const -> decltype(ctx.out()) {
|
||||
auto specs = specs_;
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs.width,
|
||||
specs.width_ref, ctx);
|
||||
detail::handle_dynamic_spec<detail::precision_checker>(
|
||||
specs_.precision, specs_.precision_ref, ctx);
|
||||
return detail::write_bytes(ctx.out(), b.data_, specs_);
|
||||
specs.precision, specs.precision_ref, ctx);
|
||||
return detail::write_bytes(ctx.out(), b.data_, specs);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4162,15 +4163,16 @@ template <typename T> struct formatter<group_digits_view<T>> : formatter<T> {
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(group_digits_view<T> t, FormatContext& ctx)
|
||||
auto format(group_digits_view<T> t, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs_.width,
|
||||
specs_.width_ref, ctx);
|
||||
auto specs = specs_;
|
||||
detail::handle_dynamic_spec<detail::width_checker>(specs.width,
|
||||
specs.width_ref, ctx);
|
||||
detail::handle_dynamic_spec<detail::precision_checker>(
|
||||
specs_.precision, specs_.precision_ref, ctx);
|
||||
return detail::write_int(
|
||||
ctx.out(), static_cast<detail::uint64_or_128_t<T>>(t.value), 0, specs_,
|
||||
detail::digit_grouping<char>("\3", ","));
|
||||
specs.precision, specs.precision_ref, ctx);
|
||||
return detail::write_int(ctx.out(),
|
||||
static_cast<detail::uint64_or_128_t<T>>(t.value),
|
||||
0, specs, detail::digit_grouping<char>("\3", ","));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user