Move named_arg to public API (#4687)

This commit is contained in:
TPPPP 2026-03-01 07:34:39 +08:00 committed by GitHub
parent 88c5a91487
commit db4bea83d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 6 deletions

View File

@ -113,8 +113,7 @@ FMT_EXPORT template <typename Context> class dynamic_format_arg_store {
data_.emplace_back(arg);
}
template <typename T>
void emplace_arg(const detail::named_arg<T, char_type>& arg) {
template <typename T> void emplace_arg(const named_arg<T, char_type>& arg) {
if (named_info_.empty())
data_.insert(data_.begin(), basic_format_arg<Context>(nullptr, 0));
data_.emplace_back(detail::unwrap(arg.value));
@ -183,8 +182,7 @@ FMT_EXPORT template <typename Context> 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 <typename T>
void push_back(const detail::named_arg<T, char_type>& arg) {
template <typename T> void push_back(const named_arg<T, char_type>& arg) {
const char_type* arg_name =
dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
if FMT_CONSTEXPR20 (need_copy<T>::value) {

View File

@ -2342,6 +2342,9 @@ inline void vprint_mojibake(FILE*, string_view, const format_args&, bool) {}
// The main public API.
template <typename T, typename Char = char>
using named_arg = detail::named_arg<T, Char>;
template <typename Char>
FMT_CONSTEXPR void parse_context<Char>::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 <typename T>
inline auto arg(const char* name, const T& arg) -> detail::named_arg<T> {
inline auto arg(const char* name, const T& arg) -> named_arg<T> {
return {name, arg};
}

View File

@ -137,7 +137,7 @@ inline auto operator""_a(const wchar_t* s, size_t) -> detail::udl_arg<wchar_t> {
#endif
template <typename T>
auto arg(const wchar_t* name, const T& arg) -> detail::named_arg<T, wchar_t> {
auto arg(const wchar_t* name, const T& arg) -> named_arg<T, wchar_t> {
return {name, arg};
}