Skip to content

Commit 835b910

Browse files
committed
Add an is_formattable trait
1 parent 5788740 commit 835b910

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

include/fmt/core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,11 @@ using wformat_context = buffer_context<wchar_t>;
15251525
#define FMT_BUFFER_CONTEXT(Char) \
15261526
basic_format_context<detail::buffer_appender<Char>, Char>
15271527

1528+
template <typename T, typename Char = char>
1529+
using is_formattable = bool_constant<!std::is_same<
1530+
decltype(detail::arg_mapper<buffer_context<Char>>().map(std::declval<T>())),
1531+
detail::unformattable>::value>;
1532+
15281533
/**
15291534
\rst
15301535
An array of references to arguments. It can be implicitly converted into

test/core-test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,12 @@ TEST(CoreTest, HasFormatter) {
617617
"");
618618
}
619619

620+
TEST(CoreTest, IsFormattable) {
621+
static_assert(fmt::is_formattable<enabled_formatter>::value, "");
622+
static_assert(!fmt::is_formattable<disabled_formatter>::value, "");
623+
static_assert(fmt::is_formattable<disabled_formatter_convertible>::value, "");
624+
}
625+
620626
struct convertible_to_int {
621627
operator int() const { return 42; }
622628
};

0 commit comments

Comments
 (0)