Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,7 @@ template <typename Context> class value {
template <typename T, FMT_ENABLE_IF(!has_formatter<T, char_type>())>
FMT_CONSTEXPR value(const T&, custom_tag) {
// Cannot format an argument; to make type T formattable provide a
// formatter<T> specialization: https://fmt.dev/latest/api.html#udt.
// formatter<T> specialization: https://fmt.dev/latest/api#udt.
type_is_unformattable_for<T, char_type> _;
}

Expand Down Expand Up @@ -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 <typename Char, typename T>
inline auto arg(const Char* name, const T& arg) -> detail::named_arg<Char, T> {
Expand Down
8 changes: 8 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,14 @@ template <typename T, typename Char = char> 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);
*/
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's already a similar docstring in the #else block below, but it doesn't show up in the rendered documentation.

template <detail::fixed_string S> constexpr auto operator""_a() {
using char_t = remove_cvref_t<decltype(*S.data)>;
return detail::udl_arg<char_t, sizeof(S.data) / sizeof(char_t), S>();
Expand Down