I am using std::format inside my assert macro. Inside a custom container I want to write:
assert( is_found(key) ) << std::format( “The key ‘{}’ was not found”, key );
The issue is that the type of the key is used supplied, and I do not want to force the caller to implement a custom formatter for the type, but for types that ARE defined, it is really helpful. When a formatter is not available I want to write:
The key ‘(no user supplied formatter)’ was not found.
Is there anything existing like that?
I would be opkay write:
assert( is_found(key) ) << std::format( “The key ‘{}’ was not found”, TryToFormat(key) );
Where TryToFormat would return key of type T if a formatter exists, but return MissingT if it doesn’t. I would then write a formatter for MissingT<> that handles the output of a missing key.
I hope I’m being clear.