mirror of
https://github.com/fmtlib/fmt.git
synced 2025-03-25 10:43:49 +00:00
Simplify mapped_type_constant
This commit is contained in:
parent
4986b4c0ef
commit
9f29345ea0
@ -84,7 +84,7 @@ class dynamic_format_arg_store
|
|||||||
|
|
||||||
template <typename T> struct need_copy {
|
template <typename T> struct need_copy {
|
||||||
static constexpr detail::type mapped_type =
|
static constexpr detail::type mapped_type =
|
||||||
detail::mapped_type_constant<T, Context>::value;
|
detail::mapped_type_constant<T, char_type>::value;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
value = !(detail::is_reference_wrapper<T>::value ||
|
value = !(detail::is_reference_wrapper<T>::value ||
|
||||||
|
@ -1028,14 +1028,12 @@ template <typename T, typename Char>
|
|||||||
using mapped_t = decltype(detail::arg_mapper<Char>::map(std::declval<T&>()));
|
using mapped_t = decltype(detail::arg_mapper<Char>::map(std::declval<T&>()));
|
||||||
|
|
||||||
// A type constant after applying arg_mapper.
|
// A type constant after applying arg_mapper.
|
||||||
template <typename T, typename Context>
|
template <typename T, typename Char = char>
|
||||||
using mapped_type_constant =
|
using mapped_type_constant = type_constant<mapped_t<T, Char>, Char>;
|
||||||
type_constant<decltype(arg_mapper<typename Context::char_type>::map(
|
|
||||||
std::declval<const T&>())),
|
|
||||||
typename Context::char_type>;
|
|
||||||
|
|
||||||
template <typename T, typename Context,
|
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<
|
using stored_type_constant = std::integral_constant<
|
||||||
type, Context::builtin_types || TYPE == type::int_type ? TYPE
|
type, Context::builtin_types || TYPE == type::int_type ? TYPE
|
||||||
: type::custom_type>;
|
: type::custom_type>;
|
||||||
@ -1801,7 +1799,7 @@ class format_string_checker {
|
|||||||
template <typename... T>
|
template <typename... T>
|
||||||
explicit FMT_CONSTEXPR format_string_checker(basic_string_view<Char> fmt,
|
explicit FMT_CONSTEXPR format_string_checker(basic_string_view<Char> fmt,
|
||||||
arg_pack<T...>)
|
arg_pack<T...>)
|
||||||
: types_{mapped_type_constant<T, buffered_context<Char>>::value...},
|
: types_{mapped_type_constant<T, Char>::value...},
|
||||||
named_args_{},
|
named_args_{},
|
||||||
context_(fmt, NUM_ARGS, types_),
|
context_(fmt, NUM_ARGS, types_),
|
||||||
parse_funcs_{&invoke_parse<T, Char>...} {
|
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>
|
template <typename T, typename Enable = void>
|
||||||
struct locking : bool_constant<mapped_type_constant<T, context>::value ==
|
struct locking
|
||||||
type::custom_type> {};
|
: bool_constant<mapped_type_constant<T>::value == type::custom_type> {};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct locking<T, void_t<typename formatter<remove_cvref_t<T>>::nonlocking>>
|
struct locking<T, void_t<typename formatter<remove_cvref_t<T>>::nonlocking>>
|
||||||
: std::false_type {};
|
: std::false_type {};
|
||||||
|
@ -1084,7 +1084,7 @@ class loc_value {
|
|||||||
public:
|
public:
|
||||||
template <typename T, FMT_ENABLE_IF(!detail::is_float128<T>::value)>
|
template <typename T, FMT_ENABLE_IF(!detail::is_float128<T>::value)>
|
||||||
loc_value(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);
|
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.
|
// FMT_ENABLE_IF() condition separated to workaround an MSVC bug.
|
||||||
template <
|
template <
|
||||||
typename Char, typename OutputIt, typename T,
|
typename Char, typename OutputIt, typename T,
|
||||||
bool check =
|
bool check = std::is_enum<T>::value && !std::is_same<T, Char>::value &&
|
||||||
std::is_enum<T>::value && !std::is_same<T, Char>::value &&
|
mapped_type_constant<T, Char>::value != type::custom_type,
|
||||||
mapped_type_constant<T, basic_format_context<OutputIt, Char>>::value !=
|
|
||||||
type::custom_type,
|
|
||||||
FMT_ENABLE_IF(check)>
|
FMT_ENABLE_IF(check)>
|
||||||
FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
|
FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
|
||||||
return write<Char>(out, static_cast<underlying_t<T>>(value));
|
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,
|
template <typename Char, typename OutputIt, typename T,
|
||||||
typename Context = basic_format_context<OutputIt, Char>>
|
FMT_ENABLE_IF(mapped_type_constant<T, Char>::value ==
|
||||||
FMT_CONSTEXPR auto write(OutputIt out, const T& value)
|
|
||||||
-> enable_if_t<mapped_type_constant<T, Context>::value ==
|
|
||||||
type::custom_type &&
|
type::custom_type &&
|
||||||
!std::is_fundamental<T>::value,
|
!std::is_fundamental<T>::value)>
|
||||||
OutputIt> {
|
FMT_CONSTEXPR auto write(OutputIt out, const T& value) -> OutputIt {
|
||||||
auto formatter = typename Context::template formatter_type<T>();
|
auto f = formatter<T, Char>();
|
||||||
auto parse_ctx = typename Context::parse_context_type({});
|
auto parse_ctx = parse_context<Char>({});
|
||||||
formatter.parse(parse_ctx);
|
f.parse(parse_ctx);
|
||||||
auto ctx = Context(out, {}, {});
|
auto ctx = basic_format_context<OutputIt, Char>(out, {}, {});
|
||||||
return formatter.format(value, ctx);
|
return f.format(value, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user