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:
parent
f8e00a084a
commit
dc56728e3a
@ -1097,7 +1097,10 @@ template <typename Context> class value {
|
|||||||
Context& ctx) {
|
Context& ctx) {
|
||||||
Formatter f;
|
Formatter f;
|
||||||
parse_ctx.advance_to(f.parse(parse_ctx));
|
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));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -257,7 +257,7 @@ struct formatter<RangeT, Char,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
typename FormatContext::iterator format(const RangeT& values,
|
typename FormatContext::iterator format(RangeT& values,
|
||||||
FormatContext& ctx) {
|
FormatContext& ctx) {
|
||||||
auto out = detail::copy(formatting.prefix, ctx.out());
|
auto out = detail::copy(formatting.prefix, ctx.out());
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user