New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fmtlib support #2780
Comments
I'd love this too; we have tried a few times unsuccessfully to hack it ourselves |
I am okay with this feature, but there are some things that need to be satisfactorily answered
|
I recently added The concept below closely aligns with the c++23 namespace dp::concepts {
// helper
template <typename T, typename Context, typename Formatter = Context::template formatter_type<std::remove_const_t<T>>>
concept FormattableWithHelper = std::semiregular<Formatter> &&
requires(Formatter& f, const Formatter& cf, T&& t, Context fc, std::basic_format_parse_context<typename Context::char_type> pc) {
{ f.parse(pc) } -> std::same_as<typename decltype(pc)::iterator>;
{ cf.format(t, fc) } -> std::same_as<typename Context::iterator>;
};
// check if type is formattable with std::format
template <typename T, typename CharT = char>
concept Formattable = FormattableWithHelper<std::remove_reference_t<T>, std::basic_format_context<std::back_insert_iterator<std::basic_string<CharT>>, CharT>>;
} // namespace dp::concepts Then just need tiny template #include <catch2/catch_test_macros.hpp>
#include <format>
// Catch2 StringMaker specialization
namespace Catch {
template<dp::concepts::Formattable T>
struct StringMaker<T> {
static std::string convert(const T& t) {
return std::format("{}", t);
}
};
} |
I can make a PR for native I would need to know from the core Catch2 team their philosophy on stringify priorities. I'm rather agnostic. I have noticed a general disdain of iostreams where std::format is available. This suggest to me that it should be before even |
Description
We have a codebase whose data structures can be printed via custom fmtlib formatters. It'd be great if Catch could detect these formatters automatically and use them.
Additional context
I've started experimenting with introducing this into your codebase - but wanted to check if it's even a desired feature of catch2 before proceeding:
Naively, the easiest approach to this would be to copy what's done for
operator<<
in catch_tostring.hpp - in addition to [IsStreamInsertable] (Catch2/src/catch2/catch_tostring.hpp
Line 68 in 53d0d91
We could hook into
__has_include
to see if fmtlib is even present, and if not,ifdef
all that stuff out.The text was updated successfully, but these errors were encountered: