Simplify make_format_args

This commit is contained in:
Victor Zverovich 2024-01-09 19:12:31 -08:00
parent cf8426cf8c
commit 4d616479b5

View File

@ -200,12 +200,12 @@ FMT_END_NAMESPACE_STD
# endif # endif
#endif #endif
#ifndef FMT_INLINE #ifdef FMT_INLINE
# if FMT_GCC_VERSION || FMT_CLANG_VERSION // Use the provided definition.
# define FMT_INLINE inline __attribute__((always_inline)) #elif FMT_GCC_VERSION || FMT_CLANG_VERSION
# else # define FMT_INLINE inline __attribute__((always_inline))
# define FMT_INLINE inline #else
# endif # define FMT_INLINE inline
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
@ -1523,6 +1523,12 @@ constexpr auto encode_types() -> unsigned long long {
(encode_types<Context, Args...>() << packed_arg_bits); (encode_types<Context, Args...>() << packed_arg_bits);
} }
template <typename Context, typename... T, size_t NUM_ARGS = sizeof...(T)>
constexpr unsigned long long make_descriptor() {
return NUM_ARGS <= max_packed_args ? encode_types<Context, T...>()
: is_unpacked_bit | NUM_ARGS;
}
#if defined(__cpp_if_constexpr) #if defined(__cpp_if_constexpr)
// This type is intentionally undefined, only used for errors // This type is intentionally undefined, only used for errors
template <typename T, typename Char> struct type_is_unformattable_for; template <typename T, typename Char> struct type_is_unformattable_for;
@ -1932,29 +1938,21 @@ using is_formattable = bool_constant<!std::is_base_of<
template <typename Context = format_context, typename... T, template <typename Context = format_context, typename... T,
size_t NUM_ARGS = sizeof...(T), size_t NUM_ARGS = sizeof...(T),
size_t NUM_NAMED_ARGS = detail::count_named_args<T...>(), size_t NUM_NAMED_ARGS = detail::count_named_args<T...>(),
unsigned long long DESC = NUM_ARGS <= detail::max_packed_args unsigned long long DESC = detail::make_descriptor<Context, T...>(),
? detail::encode_types<Context, T...>()
: detail::is_unpacked_bit | NUM_ARGS,
FMT_ENABLE_IF(NUM_NAMED_ARGS == 0)> FMT_ENABLE_IF(NUM_NAMED_ARGS == 0)>
constexpr auto make_format_args(T&... args) constexpr auto make_format_args(T&... args)
-> detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC> { -> detail::format_arg_store<Context, NUM_ARGS, 0, DESC> {
return {{detail::make_arg<NUM_ARGS <= detail::max_packed_args, Context>( return {{detail::make_arg<NUM_ARGS <= detail::max_packed_args, Context>(
args)...}}; args)...}};
} }
template <typename Context = format_context, typename... T, template <typename Context = format_context, typename... T,
size_t NUM_ARGS = sizeof...(T),
size_t NUM_NAMED_ARGS = detail::count_named_args<T...>(), size_t NUM_NAMED_ARGS = detail::count_named_args<T...>(),
unsigned long long DESC = unsigned long long DESC = detail::make_descriptor<Context, T...>() |
(NUM_ARGS <= detail::max_packed_args static_cast<unsigned long long>(detail::has_named_args_bit),
? detail::encode_types<Context, T...>()
: detail::is_unpacked_bit | NUM_ARGS) |
(NUM_NAMED_ARGS != 0
? static_cast<unsigned long long>(detail::has_named_args_bit)
: 0),
FMT_ENABLE_IF(NUM_NAMED_ARGS != 0)> FMT_ENABLE_IF(NUM_NAMED_ARGS != 0)>
constexpr auto make_format_args(T&... args) constexpr auto make_format_args(T&... args)
-> detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC> { -> detail::format_arg_store<Context, sizeof...(T), NUM_NAMED_ARGS, DESC> {
return {args...}; return {args...};
} }