is_const_formattable -> has_const_formatter

This commit is contained in:
Victor Zverovich 2021-09-05 08:35:08 -07:00
parent 2fe94ad7e3
commit 6b55c83252
2 changed files with 10 additions and 10 deletions

View File

@ -684,19 +684,19 @@ class appender;
FMT_BEGIN_DETAIL_NAMESPACE FMT_BEGIN_DETAIL_NAMESPACE
template <typename Context, typename T> template <typename Context, typename T>
constexpr auto is_const_formattable_impl(T*) constexpr auto has_const_formatter_impl(T*)
-> decltype(typename Context::template formatter_type<T>().format( -> decltype(typename Context::template formatter_type<T>().format(
std::declval<const T&>(), std::declval<Context&>()), std::declval<const T&>(), std::declval<Context&>()),
true) { true) {
return true; return true;
} }
template <typename Context> template <typename Context>
constexpr auto is_const_formattable_impl(...) -> bool { constexpr auto has_const_formatter_impl(...) -> bool {
return false; return false;
} }
template <typename T, typename Context> template <typename T, typename Context>
constexpr auto is_const_formattable() -> bool { constexpr auto has_const_formatter() -> bool {
return is_const_formattable_impl<Context>(static_cast<T*>(nullptr)); return has_const_formatter_impl<Context>(static_cast<T*>(nullptr));
} }
// Extracts a reference to the container from back_insert_iterator. // Extracts a reference to the container from back_insert_iterator.
@ -1186,7 +1186,7 @@ template <typename Context> class value {
auto f = Formatter(); auto f = Formatter();
parse_ctx.advance_to(f.parse(parse_ctx)); parse_ctx.advance_to(f.parse(parse_ctx));
using qualified_type = using qualified_type =
conditional_t<is_const_formattable<T, Context>(), const T, T>; conditional_t<has_const_formatter<T, Context>(), const T, T>;
ctx.advance_to(f.format(*static_cast<qualified_type*>(arg), ctx)); ctx.advance_to(f.format(*static_cast<qualified_type*>(arg), ctx));
} }
}; };
@ -1335,7 +1335,7 @@ template <typename Context> struct arg_mapper {
template <typename T, typename U = remove_cvref_t<T>> template <typename T, typename U = remove_cvref_t<T>>
struct formattable struct formattable
: bool_constant<is_const_formattable<U, Context>() || : bool_constant<has_const_formatter<U, Context>() ||
!std::is_const<remove_reference_t<T>>::value || !std::is_const<remove_reference_t<T>>::value ||
has_fallback_formatter<U, char_type>::value> {}; has_fallback_formatter<U, char_type>::value> {};

View File

@ -891,11 +891,11 @@ TEST(core_test, adl) {
fmt::print(stdout, "{}", s); fmt::print(stdout, "{}", s);
} }
TEST(core_test, is_const_formattable) { TEST(core_test, has_const_formatter) {
EXPECT_TRUE((fmt::detail::is_const_formattable<const_formattable, EXPECT_TRUE((fmt::detail::has_const_formatter<const_formattable,
fmt::format_context>()));
EXPECT_FALSE((fmt::detail::has_const_formatter<nonconst_formattable,
fmt::format_context>())); fmt::format_context>()));
EXPECT_FALSE((fmt::detail::is_const_formattable<nonconst_formattable,
fmt::format_context>()));
} }
TEST(core_test, format_nonconst) { TEST(core_test, format_nonconst) {