From db4bea83d615facc0506c0151fc64fe8a9e139d4 Mon Sep 17 00:00:00 2001 From: TPPPP <90049492+TPPPP72@users.noreply.github.com> Date: Sun, 1 Mar 2026 07:34:39 +0800 Subject: [PATCH] Move named_arg to public API (#4687) --- include/fmt/args.h | 6 ++---- include/fmt/base.h | 5 ++++- include/fmt/xchar.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index f3f454b8..7b04ef0d 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -113,8 +113,7 @@ FMT_EXPORT template class dynamic_format_arg_store { data_.emplace_back(arg); } - template - void emplace_arg(const detail::named_arg& arg) { + template void emplace_arg(const named_arg& arg) { if (named_info_.empty()) data_.insert(data_.begin(), basic_format_arg(nullptr, 0)); data_.emplace_back(detail::unwrap(arg.value)); @@ -183,8 +182,7 @@ FMT_EXPORT template class dynamic_format_arg_store { * formatting function. `std::reference_wrapper` is supported to avoid * copying of the argument. The name is always copied into the store. */ - template - void push_back(const detail::named_arg& arg) { + template void push_back(const named_arg& arg) { const char_type* arg_name = dynamic_args_.push>(arg.name).c_str(); if FMT_CONSTEXPR20 (need_copy::value) { diff --git a/include/fmt/base.h b/include/fmt/base.h index cd9a794f..9fba386a 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2342,6 +2342,9 @@ inline void vprint_mojibake(FILE*, string_view, const format_args&, bool) {} // The main public API. +template +using named_arg = detail::named_arg; + template FMT_CONSTEXPR void parse_context::do_check_arg_id(int arg_id) { // Argument id is only checked at compile time during parsing because @@ -2718,7 +2721,7 @@ using vargs = * sufficiently new compilers. See `operator""_a()`. */ template -inline auto arg(const char* name, const T& arg) -> detail::named_arg { +inline auto arg(const char* name, const T& arg) -> named_arg { return {name, arg}; } diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 9ba1b90b..5513b852 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -137,7 +137,7 @@ inline auto operator""_a(const wchar_t* s, size_t) -> detail::udl_arg { #endif template -auto arg(const wchar_t* name, const T& arg) -> detail::named_arg { +auto arg(const wchar_t* name, const T& arg) -> named_arg { return {name, arg}; }