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:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user