Skip to content

How to re-use existing external Fmt formatters? #657

Answered by odygrd
espakm asked this question in Q&A
Discussion options

You must be logged in to vote

Hey!

Unfortunately, you need to define the specializations explicitly. As far as I know, C++ doesn't allow defining a generic specialization since the primary template isn't accessible.

You can derive from fmt::formatter, but you'll need to template both parse and format so they work with different Context types. However, if you're deriving from ostream_formatter, this approach won't work since parse isn't templated.

I've put together an example showcasing a few different possibilities. Hope it helps

https://godbolt.org/z/5Wsf5WY6P

Replies: 6 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by espakm
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@odygrd
Comment options

Comment options

You must be logged in to vote
1 reply
@odygrd
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants