Skip to content
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

Merged
merged 28 commits into from
May 9, 2020

Conversation

vsolontsov-ll
Copy link
Contributor

@vsolontsov-ll vsolontsov-ll commented May 3, 2020

vsolontsov-ll and others added 24 commits March 9, 2020 20:50
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
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
Copy link
Contributor

@vitaut vitaut left a 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.

include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
@vsolontsov-ll
Copy link
Contributor Author

@vitaut , could you take a look eventually?

@vitaut
Copy link
Contributor

vitaut commented May 8, 2020

Will take a look shortly, sorry for slow response.

Copy link
Contributor

@vitaut vitaut left a 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>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
@@ -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));
Copy link
Contributor

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.

Copy link
Contributor Author

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));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@vitaut vitaut merged commit 6820183 into fmtlib:master May 9, 2020
@vitaut
Copy link
Contributor

vitaut commented May 9, 2020

Thank you, great work!

@vsolontsov-ll vsolontsov-ll deleted the master branch May 11, 2020 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic construction of *named* argument lists?
2 participants