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

It doesn't seem to be possible to declare a funciton that can take compiled format string as an argument without referencing fmt::detail #4335

Closed
SwooshyCueb opened this issue Jan 31, 2025 · 3 comments · Fixed by #4342

Comments

@SwooshyCueb
Copy link
Contributor

Writing a function that can take a regular format string as an argument is pretty straightforward:
https://github.com/SwooshyCueb/irods/blob/5ceb3b6b99b19478ebb9f1681d3432f1e037472d/server/core/include/irods/notify_service_manager.hpp#L46-L70

However, I can't figure out how to declare an overload that can take a compiled format string without dipping into fmt::detail:
https://github.com/SwooshyCueb/irods/blob/5ceb3b6b99b19478ebb9f1681d3432f1e037472d/server/core/include/irods/notify_service_manager.hpp#L72-L99

There doesn't seem to be any documentation on how this might be done. Is this the proper solution?

@madscientist
Copy link

I don't know if this is exactly the best way, but this is how I do it. For a variadic function that takes a format string plus arguments:

    template <typename... Args>
    void fmt(fmt::format_string<Args...> fmt, Args&&... args)
    { vfmt(fmt, fmt::make_format_args(args...)); }

then to define the vfmt() method that accepts an already-compiled set of stuff it's just:

    void vfmt(fmt::string_view fmt, fmt::format_args args) { auto msg = fmt::vformat(fmt, args); }

Is that helpful?

@SwooshyCueb
Copy link
Contributor Author

That doesn't seem to work: https://godbolt.org/z/cze1sv1qf

@vitaut
Copy link
Contributor

vitaut commented Feb 1, 2025

You are right that this relies on the internal APIs at the moment. A PR to move is_compiled_string to the public API would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants