mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
get_type -> mapped_type_constant
This commit is contained in:
parent
a48daa60e5
commit
87fbc6f756
@ -827,6 +827,12 @@ template <typename Context> struct arg_mapper {
|
||||
}
|
||||
};
|
||||
|
||||
// A type constant after applying arg_mapper<Context>.
|
||||
template <typename T, typename Context>
|
||||
using mapped_type_constant =
|
||||
type_constant<decltype(arg_mapper<Context>().map(std::declval<T>())),
|
||||
typename Context::char_type>;
|
||||
|
||||
// Maximum number of arguments with packed types.
|
||||
enum { max_packed_args = 15 };
|
||||
enum : unsigned long long { is_unpacked_bit = 1ull << 63 };
|
||||
@ -983,22 +989,18 @@ class locale_ref {
|
||||
template <typename Locale> Locale get() const;
|
||||
};
|
||||
|
||||
template <typename Context, typename T>
|
||||
using get_type =
|
||||
type_constant<decltype(arg_mapper<Context>().map(std::declval<T>())),
|
||||
typename Context::char_type>;
|
||||
|
||||
template <typename> constexpr unsigned long long get_types() { return 0; }
|
||||
|
||||
template <typename Context, typename Arg, typename... Args>
|
||||
constexpr unsigned long long get_types() {
|
||||
return get_type<Context, Arg>::value | (get_types<Context, Args...>() << 4);
|
||||
return mapped_type_constant<Arg, Context>::value |
|
||||
(get_types<Context, Args...>() << 4);
|
||||
}
|
||||
|
||||
template <typename Context, typename T>
|
||||
FMT_CONSTEXPR basic_format_arg<Context> make_arg(const T& value) {
|
||||
basic_format_arg<Context> arg;
|
||||
arg.type_ = get_type<Context, T>::value;
|
||||
arg.type_ = mapped_type_constant<T, Context>::value;
|
||||
arg.value_ = arg_mapper<Context>().map(value);
|
||||
return arg;
|
||||
}
|
||||
|
@ -3165,7 +3165,8 @@ template <typename Char = char> class dynamic_formatter {
|
||||
auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) {
|
||||
handle_specs(ctx);
|
||||
internal::specs_checker<null_handler> checker(
|
||||
null_handler(), internal::get_type<FormatContext, T>::value);
|
||||
null_handler(),
|
||||
internal::mapped_type_constant<T, FormatContext>::value);
|
||||
checker.on_align(specs_.align());
|
||||
if (specs_.flags == 0)
|
||||
; // Do nothing.
|
||||
|
@ -567,15 +567,18 @@ TEST(CoreTest, ToStringViewForeignStrings) {
|
||||
EXPECT_EQ(to_string_view(my_string<wchar_t>(L"42")), L"42");
|
||||
EXPECT_EQ(to_string_view(QString(L"42")), L"42");
|
||||
fmt::internal::type type =
|
||||
fmt::internal::get_type<fmt::format_context, my_string<char>>::value;
|
||||
fmt::internal::mapped_type_constant<my_string<char>,
|
||||
fmt::format_context>::value;
|
||||
EXPECT_EQ(type, fmt::internal::string_type);
|
||||
type = fmt::internal::mapped_type_constant<my_string<wchar_t>,
|
||||
fmt::wformat_context>::value;
|
||||
EXPECT_EQ(type, fmt::internal::string_type);
|
||||
type =
|
||||
fmt::internal::get_type<fmt::wformat_context, my_string<wchar_t>>::value;
|
||||
EXPECT_EQ(type, fmt::internal::string_type);
|
||||
type = fmt::internal::get_type<fmt::wformat_context, QString>::value;
|
||||
fmt::internal::mapped_type_constant<QString, fmt::wformat_context>::value;
|
||||
EXPECT_EQ(type, fmt::internal::string_type);
|
||||
// Does not compile: only wide format contexts are compatible with QString!
|
||||
// type = fmt::internal::get_type<fmt::format_context, QString>::value;
|
||||
// type = fmt::internal::mapped_type_constant<QString,
|
||||
// fmt::format_context>::value;
|
||||
}
|
||||
|
||||
TEST(CoreTest, FormatForeignStrings) {
|
||||
|
@ -643,7 +643,7 @@ struct formatter {
|
||||
FMT_CONSTEXPR typename ParseContext::iterator parse(ParseContext& ctx) {
|
||||
namespace internal = fmt::internal;
|
||||
typedef internal::dynamic_specs_handler<ParseContext> handler_type;
|
||||
auto type = internal::get_type<fmt::buffer_context<Char>, T>::value;
|
||||
auto type = internal::mapped_type_constant<T, fmt::buffer_context<Char>>::value;
|
||||
internal::specs_checker<handler_type> handler(handler_type(specs_, ctx),
|
||||
type);
|
||||
auto it = parse_format_specs(ctx.begin(), ctx.end(), handler);
|
||||
|
Loading…
Reference in New Issue
Block a user