Fix format_as for non-const begin/end views (#3955)

base::format does not accept rvalues, using the result of format_as
directly means it is passed one. Doesn't matter for ranges with a const
begin and end, but filter_view caches, so it only has mutable begin/end.
Use auto&& to avoid copy if format_as returns const ref
This commit is contained in:
Justin Riddell
2024-05-13 09:35:55 -07:00
committed by GitHub
parent 1f436c646e
commit 8e728044f6
2 changed files with 45 additions and 6 deletions
+3 -1
View File
@@ -4000,7 +4000,9 @@ struct formatter<T, Char, enable_if_t<detail::has_format_as<T>::value>>
template <typename FormatContext>
auto format(const T& value, FormatContext& ctx) const -> decltype(ctx.out()) {
using base = formatter<detail::format_as_t<T>, Char>;
return base::format(format_as(value), ctx);
// format functions expect lvalue refs, not rvalues
auto&& val = format_as(value);
return base::format(val, ctx);
}
};