From 0aca816f7d5daed0a92aac9aa2588cd76b1bd408 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 16 Dec 2025 16:23:43 +0700 Subject: [PATCH] Some documentation improvements --- doc/api.md | 2 -- include/fmt/base.h | 6 +++++- include/fmt/format.h | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/api.md b/doc/api.md index 9fbc9f2f..c7f05a2c 100644 --- a/doc/api.md +++ b/doc/api.md @@ -321,8 +321,6 @@ parameterized version. ::: arg(const Char*, const T&) -Named arguments are not supported in compile-time checks at the moment. - ### Compatibility ::: basic_string_view diff --git a/include/fmt/base.h b/include/fmt/base.h index 0d578677..84f92fae 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2306,7 +2306,7 @@ template class value { template ())> FMT_CONSTEXPR value(const T&, custom_tag) { // Cannot format an argument; to make type T formattable provide a - // formatter specialization: https://fmt.dev/latest/api.html#udt. + // formatter specialization: https://fmt.dev/latest/api#udt. type_is_unformattable_for _; } @@ -2841,6 +2841,10 @@ using vargs = * **Example**: * * fmt::print("The answer is {answer}.", fmt::arg("answer", 42)); + * + * Named arguments passed with `fmt::arg` are not supported + * in compile-time checks, but `"answer"_a=42` are compile-time checked in + * sufficiently new compilers. See `operator""_a()`. */ template inline auto arg(const Char* name, const T& arg) -> detail::named_arg { diff --git a/include/fmt/format.h b/include/fmt/format.h index 4a653007..f222da96 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -4142,6 +4142,14 @@ template struct nested_formatter { inline namespace literals { #if FMT_USE_NONTYPE_TEMPLATE_ARGS +/** + * User-defined literal equivalent of `fmt::arg`, but with compile-time checks. + * + * **Example**: + * + * using namespace fmt::literals; + * fmt::print("The answer is {answer}.", "answer"_a=42); + */ template constexpr auto operator""_a() { using char_t = remove_cvref_t; return detail::udl_arg();