mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-09 21:00:06 +00:00
Reduce the number of instantiations
This commit is contained in:
parent
60740b7c24
commit
bc3af51272
@ -876,20 +876,20 @@ template <typename T> struct format_as_result {
|
|||||||
};
|
};
|
||||||
template <typename T> using format_as_t = typename format_as_result<T>::type;
|
template <typename T> using format_as_t = typename format_as_result<T>::type;
|
||||||
|
|
||||||
template <typename Context, typename T>
|
template <typename Char, typename T>
|
||||||
constexpr auto has_const_formatter_impl(T*)
|
constexpr auto has_const_formatter_impl(T*)
|
||||||
-> decltype(typename Context::template formatter_type<T>().format(
|
-> decltype(formatter<T, Char>().format(
|
||||||
std::declval<const T&>(), std::declval<Context&>()),
|
std::declval<const T&>(),
|
||||||
|
std::declval<buffered_context<Char>&>()),
|
||||||
true) {
|
true) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template <typename Context>
|
template <typename Char> constexpr auto has_const_formatter_impl(...) -> bool {
|
||||||
constexpr auto has_const_formatter_impl(...) -> bool {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
template <typename T, typename Context>
|
template <typename T, typename Char>
|
||||||
constexpr auto has_const_formatter() -> bool {
|
constexpr auto has_const_formatter() -> bool {
|
||||||
return has_const_formatter_impl<Context>(static_cast<T*>(nullptr));
|
return has_const_formatter_impl<Char>(static_cast<T*>(nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct unformattable {};
|
struct unformattable {};
|
||||||
@ -1002,7 +1002,7 @@ template <typename Context> struct arg_mapper {
|
|||||||
|
|
||||||
template <typename T, typename U = remove_const_t<T>>
|
template <typename T, typename U = remove_const_t<T>>
|
||||||
struct formattable
|
struct formattable
|
||||||
: bool_constant<has_const_formatter<U, Context>() ||
|
: bool_constant<has_const_formatter<U, char_type>() ||
|
||||||
(std::is_constructible<formatter<U, char_type>>::value &&
|
(std::is_constructible<formatter<U, char_type>>::value &&
|
||||||
!std::is_const<T>::value)> {};
|
!std::is_const<T>::value)> {};
|
||||||
|
|
||||||
@ -2341,7 +2341,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<has_const_formatter<T, Context>(), const T, T>;
|
conditional_t<has_const_formatter<T, char_type>(), const T, T>;
|
||||||
// format must be const for compatibility with std::format and compilation.
|
// format must be const for compatibility with std::format and compilation.
|
||||||
const auto& cf = f;
|
const auto& cf = f;
|
||||||
ctx.advance_to(cf.format(*static_cast<qualified_type*>(arg), ctx));
|
ctx.advance_to(cf.format(*static_cast<qualified_type*>(arg), ctx));
|
||||||
|
@ -820,9 +820,9 @@ TEST(base_test, format_explicitly_convertible_to_std_string_view) {
|
|||||||
|
|
||||||
TEST(base_test, has_const_formatter) {
|
TEST(base_test, has_const_formatter) {
|
||||||
EXPECT_TRUE((fmt::detail::has_const_formatter<const_formattable,
|
EXPECT_TRUE((fmt::detail::has_const_formatter<const_formattable,
|
||||||
fmt::format_context>()));
|
char>()));
|
||||||
EXPECT_FALSE((fmt::detail::has_const_formatter<nonconst_formattable,
|
EXPECT_FALSE((fmt::detail::has_const_formatter<nonconst_formattable,
|
||||||
fmt::format_context>()));
|
char>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(base_test, format_nonconst) {
|
TEST(base_test, format_nonconst) {
|
||||||
|
Loading…
Reference in New Issue
Block a user