Simplify mapped_type_constant

This commit is contained in:
Victor Zverovich 2024-09-02 06:41:44 -07:00
parent 4986b4c0ef
commit 9f29345ea0
3 changed files with 20 additions and 26 deletions

View File

@ -84,7 +84,7 @@ class dynamic_format_arg_store
template <typename T> struct need_copy {
static constexpr detail::type mapped_type =
detail::mapped_type_constant<T, Context>::value;
detail::mapped_type_constant<T, char_type>::value;
enum {
value = !(detail::is_reference_wrapper<T>::value ||

View File

@ -1028,14 +1028,12 @@ template <typename T, typename Char>
using mapped_t = decltype(detail::arg_mapper<Char>::map(std::declval<T&>()));
// A type constant after applying arg_mapper.
template <typename T, typename Context>
using mapped_type_constant =
type_constant<decltype(arg_mapper<typename Context::char_type>::map(
std::declval<const T&>())),
typename Context::char_type>;
template <typename T, typename Char = char>
using mapped_type_constant = type_constant<mapped_t<T, Char>, Char>;
template <typename T, typename Context,
type TYPE = mapped_type_constant<T, Context>::value>
type TYPE =
mapped_type_constant<T, typename Context::char_type>::value>
using stored_type_constant = std::integral_constant<
type, Context::builtin_types || TYPE == type::int_type ? TYPE
: type::custom_type>;
@ -1801,7 +1799,7 @@ class format_string_checker {
template <typename... T>
explicit FMT_CONSTEXPR format_string_checker(basic_string_view<Char> fmt,
arg_pack<T...>)
: types_{mapped_type_constant<T, buffered_context<Char>>::value...},
: types_{mapped_type_constant<T, Char>::value...},
named_args_{},
context_(fmt, NUM_ARGS, types_),
parse_funcs_{&invoke_parse<T, Char>...} {
@ -2790,8 +2788,8 @@ template <typename T, typename Char, type TYPE> struct native_formatter {
};
template <typename T, typename Enable = void>
struct locking : bool_constant<mapped_type_constant<T, context>::value ==
type::custom_type> {};
struct locking
: bool_constant<mapped_type_constant<T>::value == type::custom_type> {};
template <typename T>
struct locking<T, void_t<typename formatter<remove_cvref_t<T>>::nonlocking>>
: std::false_type {};

View File

@ -1084,7 +1084,7 @@ class loc_value {
public:
template <typename T, FMT_ENABLE_IF(!detail::is_float128<T>::value)>
loc_value(T value) {
value_.type_ = detail::mapped_type_constant<T, format_context>::value;
value_.type_ = detail::mapped_type_constant<T>::value;
value_.value_ = detail::arg_mapper<char>::map(value);
}
@ -3606,10 +3606,8 @@ constexpr auto write(OutputIt out, const T& value) -> OutputIt {
// FMT_ENABLE_IF() condition separated to workaround an MSVC bug.
template <
typename Char, typename OutputIt, typename T,
bool check =
std::is_enum<T>::value && !std::is_same<T, Char>::value &&
mapped_type_constant<T, basic_format_context<OutputIt, Char>>::value !=
type::custom_type,
bool check = std::is_enum<T>::value && !std::is_same<T, Char>::value &&
mapped_type_constant<T, Char>::value != type::custom_type,
FMT_ENABLE_IF(check)>
FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
return write<Char>(out, static_cast<underlying_t<T>>(value));
@ -3659,17 +3657,15 @@ FMT_CONSTEXPR auto write(OutputIt out, const T& value) -> enable_if_t<
}
template <typename Char, typename OutputIt, typename T,
typename Context = basic_format_context<OutputIt, Char>>
FMT_CONSTEXPR auto write(OutputIt out, const T& value)
-> enable_if_t<mapped_type_constant<T, Context>::value ==
type::custom_type &&
!std::is_fundamental<T>::value,
OutputIt> {
auto formatter = typename Context::template formatter_type<T>();
auto parse_ctx = typename Context::parse_context_type({});
formatter.parse(parse_ctx);
auto ctx = Context(out, {}, {});
return formatter.format(value, ctx);
FMT_ENABLE_IF(mapped_type_constant<T, Char>::value ==
type::custom_type &&
!std::is_fundamental<T>::value)>
FMT_CONSTEXPR auto write(OutputIt out, const T& value) -> OutputIt {
auto f = formatter<T, Char>();
auto parse_ctx = parse_context<Char>({});
f.parse(parse_ctx);
auto ctx = basic_format_context<OutputIt, Char>(out, {}, {});
return f.format(value, ctx);
}
template <typename T>