fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
19.83k stars 2.42k forks source link

formatter simply inheriting from built-in formatter is not recognised #4036

Open gnbond opened 1 week ago

gnbond commented 1 week ago

libfmt 10.2 / gcc 13

I have a string-like class implicitly-convertible to std::string_view. Based on older documentation I'd expect that to Just Work in fmt::format()but I see from other issues that matching on implicit conversion has been disabled. Annoying, but fair enough.

When I create a fmt::formatter specialisation for my class that simply inherits fmt::formatter<string_view>, this does not work, fmt::format still considers S to be an un-formattable type.

template<>
class fmt::formatter<S> 
    : public fmt::formatter<std::string_view> {};

https://godbolt.org/z/aMqqWaso9

The equivalent code using std::formatter works ok: https://godbolt.org/z/T7zzKzzf3

vitaut commented 1 week ago

Right now the string_view formatter only accepts string_view and not objects convertible to it but I think it's reasonable to relax this.