-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add an API for dynamic construction of argument lists #1170
Comments
Adding on to #1168, I was working on a resume generator and ran into a similar issue. One of the features I was working on was the ability for the user to define HTML templates like below:
The main problem is that I want to be able to define the templates without having to touch C++ code. That means the parameters have to been parsed from some sort of data file, so the formatting arguments have to be constructed at runtime. In Python, I would just build a With that being said, I really liked a lot of the other features this library provided. I'm willing to help implement this if you have good pointers on where to start. |
I think the easiest solution is to implement something like |
Qt has a format API which looks like |
Adding dynamic_arg_store as described would be extremely useful. My typical use case is that I have a std::map<std::string, my_type> and I want to add one or more of these to the dynamic_arg_store and then pass this to vformat. Ideally I could keep the dynamic_arg_store around and update it in place, and also used the new compiled format object with it to speed up the operation. |
While
|
Does this support runtime determine number of arguments? i.e. I have my zero or more named args in a runtime constructed map and I want to pass them all to the Format function. |
True. Definetely no. It's only compile time wrapper for compile time variadic args function fmt::format() |
Is this feature still on the radar? |
It is but AFAIK noone is working on it at the moment. |
Hm, I'm wondering if there's something wrong with just making There's even a unit test with dynamic arguments: UPD: I realize lifetime for strings and custom objects is an issue but in may cases it's acceptable. E.g. in my case there's a binary dump and a format string to format it, char sequence is already stored in the dump, so its lifetime is guaranteed. |
Lifetime is an issue. Even though it may be acceptable in some cases, making it public would create a big footgun. |
Thank you for your answer. I will give a try to add dynamic_arg_store. As a side note I would say, it's debatable to some extent. E.g. STL doesn't prevent one from creating a container with pointers and either the programmer takes care of lifetime or UB happens. |
This has been implemented in #1584. Thanks to @vsolontsov-ll! |
Currently the number and types (but not values) of formatting arguments has to be known at compile time. Consider adding an API to allow fully dynamic construction of argument lists to support use cases like the one mentioned in #1168:
The text was updated successfully, but these errors were encountered: