Support printing of filtered views by removing const constraint

Filtered views cannot be const and have no const iterators
Note: Transformed views can be const but don't have const iterators either.

The change in ranges.h `formatter<RangeT, Char,
                         enable_if_t<fmt::is_range<RangeT, Char>::value>>::format`
is relatively benign for this reason.

However constness is cast away from the argument to `value<typename
Context>::format_custom_arg` which is in core.h -- seeminglyl pretty harmless in
a private method whout a callback.
This commit is contained in:
DV Henkel-Wallace 2020-09-03 20:14:17 -07:00
parent f8e00a084a
commit dc56728e3a
2 changed files with 5 additions and 2 deletions

View File

@ -1097,7 +1097,10 @@ template <typename Context> class value {
Context& ctx) {
Formatter f;
parse_ctx.advance_to(f.parse(parse_ctx));
ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
// We cast away any constness in order to print filtered views (ranges)
// which cannot be const
// This is a private method and we know that won't modify the object
ctx.advance_to(f.format(*const_cast<T*>(static_cast<const T*>(arg)), ctx));
}
};

View File

@ -257,7 +257,7 @@ struct formatter<RangeT, Char,
}
template <typename FormatContext>
typename FormatContext::iterator format(const RangeT& values,
typename FormatContext::iterator format(RangeT& values,
FormatContext& ctx) {
auto out = detail::copy(formatting.prefix, ctx.out());
size_t i = 0;