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

Forwarding of args in xchar.h #3408

Closed
Boddlnagg opened this issue Apr 28, 2023 · 3 comments
Closed

Forwarding of args in xchar.h #3408

Boddlnagg opened this issue Apr 28, 2023 · 3 comments

Comments

@Boddlnagg
Copy link

In the same vein as #2462, I think that format_to_n in xchar.h should take args as Args&&... instead of const Args&.... For format_to in xchar.h this is already the case.

make_wformat_args should probably also be changed to match make_format_args in forwarding the args.

@Epixu
Copy link

Epixu commented May 12, 2023

I'm currently working on a similar issue around make_format_args
They are currently taken as mutable Args&...
The comment above states that "Arguments are taken by lvalue references to avoid some lifetime issues."
And this is an implementation detail, so I suppose it's our responsibility to adapt.
Although, make_format_args is used extensively in custom formatters afaik, so the devs might still reconsider it having the proper interface eventually.

Or I might be completely missing something. Here's a custom formatter I wrote for a reference:

template<Deep T>
struct formatter<T> {
   template<class CONTEXT>
   constexpr auto parse(CONTEXT& ctx) {
      return ctx.begin();
   }

   template<class CONTEXT>
   auto format(T const& element, CONTEXT& ctx) {
      const auto asText = static_cast<Debug>(element);
      return fmt::vformat_to(ctx.out(), "{}", fmt::make_format_args(static_cast<std::string_view>(asText)));
   }
};

This currently causes error C2664 on MSVC

PP: I think this error was introduced in v. 10

@vitaut
Copy link
Contributor

vitaut commented May 12, 2023

@Epixu, make_format_args should only be used in custom formatting functions, not in custom formatters. You should use format_to instead of vformat_to:

      return fmt::format_to(ctx.out(), "{}", static_cast<std::string_view>(asText));

@vitaut
Copy link
Contributor

vitaut commented May 12, 2023

Fixed format_to signature in a425e0f.

@vitaut vitaut closed this as completed May 12, 2023
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

No branches or pull requests

3 participants