-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support named args in dynamic_format_arg_store (#1655). #1663
Conversation
named_args will be added in a separate PR. Pending: avoid Args types from dynamic_format_arg_store template parameters, replace std::forward_list<std::variant> with a custom list.
Pending: cleanup.
Removed constexpr
Pending -- move dyn-args.h to core.h
`internal::std_string_veiew` alias
Changed dispatching from tag to explicit `if`. However I would prefer tag-based dispatching if `if constexpr`, but the later is not available in older standards.
Conflicts: include/fmt/core.h test/format-dyn-args-test.cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Left a few preliminary comments inline and will take a look in details later.
@vitaut , could you take a look eventually? |
Will take a look shortly, sorry for slow response. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good, just a few more nits.
@@ -1131,6 +1132,7 @@ template <typename Context> class basic_format_arg { | |||
|
|||
friend class basic_format_args<Context>; | |||
friend class internal::arg_map<Context>; | |||
friend class dynamic_format_arg_store<Context>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, basic_format_arg
is constructed from dynamic_format_arg_store::emplace_arg()
and needs to access private ctor. Also there's a need to update named_args
with new size and pointer to array of named_arg_info
after potential relocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
include/fmt/core.h
Outdated
@@ -1500,19 +1578,53 @@ class dynamic_format_arg_store | |||
if (internal::const_check(need_copy<T>::value)) | |||
emplace_arg(dynamic_args_.push<stored_type<T>>(arg)); | |||
else | |||
emplace_arg(arg); | |||
emplace_arg(static_cast<const internal::unwrap_reference_t<T>&>(arg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Then unwrap_reference_t
can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
emplace_arg( | ||
fmt::arg(arg_name, dynamic_args_.push<stored_type<T>>(arg.value))); | ||
} else | ||
emplace_arg(fmt::arg(arg_name, arg.value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: please wrap the else condition in a compound statement ({}
) for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Thank you, great work! |
I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.