Add an is_formattable trait

This commit is contained in:
Victor Zverovich 2021-02-28 15:25:33 -08:00
parent 578874033a
commit 835b910e7d
2 changed files with 11 additions and 0 deletions

View File

@ -1525,6 +1525,11 @@ using wformat_context = buffer_context<wchar_t>;
#define FMT_BUFFER_CONTEXT(Char) \ #define FMT_BUFFER_CONTEXT(Char) \
basic_format_context<detail::buffer_appender<Char>, Char> basic_format_context<detail::buffer_appender<Char>, Char>
template <typename T, typename Char = char>
using is_formattable = bool_constant<!std::is_same<
decltype(detail::arg_mapper<buffer_context<Char>>().map(std::declval<T>())),
detail::unformattable>::value>;
/** /**
\rst \rst
An array of references to arguments. It can be implicitly converted into An array of references to arguments. It can be implicitly converted into

View File

@ -617,6 +617,12 @@ TEST(CoreTest, HasFormatter) {
""); "");
} }
TEST(CoreTest, IsFormattable) {
static_assert(fmt::is_formattable<enabled_formatter>::value, "");
static_assert(!fmt::is_formattable<disabled_formatter>::value, "");
static_assert(fmt::is_formattable<disabled_formatter_convertible>::value, "");
}
struct convertible_to_int { struct convertible_to_int {
operator int() const { return 42; } operator int() const { return 42; }
}; };