From f34f31b3210f8d10ddfe266ba4a853e0a35416da Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 8 Jan 2024 21:44:56 -0800 Subject: [PATCH] Move format_arg_store to detail --- include/fmt/core.h | 111 +++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 6ed67ad4..3bd312f2 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1099,8 +1099,6 @@ FMT_CONSTEXPR void basic_format_parse_context::check_dynamic_spec( FMT_EXPORT template class basic_format_arg; FMT_EXPORT template class basic_format_args; -FMT_EXPORT template -struct format_arg_store_impl; FMT_EXPORT template class dynamic_format_arg_store; // A formatter for objects of type T. @@ -1593,6 +1591,51 @@ template FMT_CONSTEXPR inline auto make_arg(T& val) -> basic_format_arg { return make_arg(val); } + +template +using arg_t = conditional_t, + basic_format_arg>; + +// An array of references to arguments. It can be implicitly converted to +// `fmt::basic_format_args` for passing into type-erased formatting functions +// such as `fmt::vformat`. +template +struct format_arg_store { + static const bool is_packed = NUM_ARGS <= detail::max_packed_args; + + using char_type = typename Context::char_type; + using value_type = arg_t; + + // args_[0].named_args points to named_args to avoid bloating format_args. + // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning. + value_type args_[1 + (NUM_ARGS != 0 ? NUM_ARGS : +1)]; + detail::named_arg_info named_args[NUM_NAMED_ARGS]; + + template + FMT_CONSTEXPR FMT_INLINE format_arg_store(T&... args) + : args_{{named_args, NUM_NAMED_ARGS}, + detail::make_arg(args)...} { + detail::init_named_args(named_args, 0, 0, args...); + } + + FMT_CONSTEXPR FMT_INLINE auto args() const -> const value_type* { + return args_ + 1; + } +}; + +// A specialization of format_arg_store without named arguments. +template +struct format_arg_store { + using value_type = arg_t; + + // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning. + value_type args_[NUM_ARGS != 0 ? NUM_ARGS : +1]; + + FMT_CONSTEXPR FMT_INLINE auto args() const -> const value_type* { + return args_; + } +}; } // namespace detail FMT_BEGIN_EXPORT @@ -1613,7 +1656,7 @@ template class basic_format_arg { using char_type = typename Context::char_type; template - friend struct format_arg_store_impl; + friend struct detail::format_arg_store; basic_format_arg(const detail::named_arg_info* args, size_t size) : value_(args, size) {} @@ -1763,14 +1806,14 @@ template class basic_format_args { template constexpr basic_format_args( - const format_arg_store_impl& + const detail::format_arg_store& store) : desc_(DESC), values_(store.args()) {} template detail::max_packed_args)> constexpr basic_format_args( - const format_arg_store_impl& + const detail::format_arg_store& store) : desc_(DESC), args_(store.args()) {} @@ -1895,55 +1938,6 @@ using is_formattable = bool_constant>() .map(std::declval()))>::value>; -/** - \rst - An array of references to arguments. It can be implicitly converted into - `~fmt::basic_format_args` for passing into type-erased formatting functions - such as `~fmt::vformat`. - \endrst - */ -template -struct format_arg_store_impl { - static const bool is_packed = NUM_ARGS <= detail::max_packed_args; - - using char_type = typename Context::char_type; - using value_type = conditional_t, - basic_format_arg>; - - // args_[0].named_args points to named_args to avoid bloating format_args. - // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning. - value_type args_[1 + (NUM_ARGS != 0 ? NUM_ARGS : +1)]; - detail::named_arg_info named_args[NUM_NAMED_ARGS]; - - template - FMT_CONSTEXPR FMT_INLINE format_arg_store_impl(T&... args) - : args_{value_type(named_args, NUM_NAMED_ARGS), - detail::make_arg(args)...} { - detail::init_named_args(named_args, 0, 0, args...); - } - - FMT_CONSTEXPR FMT_INLINE auto args() const -> const value_type* { - return args_ + 1; - } -}; - -// A specialization of format_arg_store_impl without named arguments. -template -struct format_arg_store_impl { - static const bool is_packed = NUM_ARGS <= detail::max_packed_args; - - using value_type = conditional_t, - basic_format_arg>; - - // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning. - value_type args_[NUM_ARGS != 0 ? NUM_ARGS : +1]; - - FMT_CONSTEXPR FMT_INLINE auto args() const -> const value_type* { - return args_; - } -}; - /** \rst Constructs an object that stores references to arguments and can be implicitly @@ -1954,16 +1948,15 @@ struct format_arg_store_impl { */ // Take arguments by lvalue references to avoid some lifetime issues, e.g. // auto args = make_format_args(std::string()); -// Use format_arg_store_impl instead of format_arg_store for shorter symbols. template (), unsigned long long DESC = NUM_ARGS <= detail::max_packed_args - ? detail::encode_types() - : detail::is_unpacked_bit | NUM_ARGS, + ? detail::encode_types() + : detail::is_unpacked_bit | NUM_ARGS, FMT_ENABLE_IF(NUM_NAMED_ARGS == 0)> constexpr auto make_format_args(T&... args) - -> format_arg_store_impl { + -> detail::format_arg_store { return {{detail::make_arg( args)...}}; } @@ -1980,7 +1973,7 @@ template constexpr auto make_format_args(T&... args) - -> format_arg_store_impl { + -> detail::format_arg_store { return {args...}; }