From 835b910e7d758efdfdce9f23df1b190deb3373db Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 28 Feb 2021 15:25:33 -0800 Subject: [PATCH] Add an is_formattable trait --- include/fmt/core.h | 5 +++++ test/core-test.cc | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/include/fmt/core.h b/include/fmt/core.h index ec729116..94b31f71 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1525,6 +1525,11 @@ using wformat_context = buffer_context; #define FMT_BUFFER_CONTEXT(Char) \ basic_format_context, Char> +template +using is_formattable = bool_constant>().map(std::declval())), + detail::unformattable>::value>; + /** \rst An array of references to arguments. It can be implicitly converted into diff --git a/test/core-test.cc b/test/core-test.cc index 50b5f9b8..5da58a60 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -617,6 +617,12 @@ TEST(CoreTest, HasFormatter) { ""); } +TEST(CoreTest, IsFormattable) { + static_assert(fmt::is_formattable::value, ""); + static_assert(!fmt::is_formattable::value, ""); + static_assert(fmt::is_formattable::value, ""); +} + struct convertible_to_int { operator int() const { return 42; } };