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

fmt::format_to_n does not work with FMT_COMPILE-d format string #1764

Closed
0xb8 opened this issue Jul 9, 2020 · 3 comments
Closed

fmt::format_to_n does not work with FMT_COMPILE-d format string #1764

0xb8 opened this issue Jul 9, 2020 · 3 comments

Comments

@0xb8
Copy link

0xb8 commented Jul 9, 2020

Example code: https://godbolt.org/z/erD-_a

In v6 fmt::format_to_n() seems to work with fmt::compile()-d format string.
In v7 though, just fmt::format_to() is working with FMT_COMPILE().

@bgemmill
Copy link

bgemmill commented Jul 9, 2020

A workaround for now is to use fmt's truncating iterator with fmt::format_to:

  static const auto formatter = FMT_COMPILE("{}");
  std::array<char, 512> s2{0};

// These two lines should be equivalent
//  auto it = fmt::format_to_n(s0.data(), 512, formatter, 42).out; // fails at compile time
  auto it = fmt::format_to(fmt::detail::truncating_iterator<char*>(s2.data(), s2.size()), formatter, 42).base();

  std::cout << s2.data() << std::endl;

@vitaut
Copy link
Contributor

vitaut commented Jul 9, 2020

A PR to add format_to_n overload that accepts FMT_COMPILE is welcome.

@vitaut
Copy link
Contributor

vitaut commented Sep 15, 2020

Implemented in #1767 and #1869. Thanks @Kurkin and @alexezeder.

@vitaut vitaut closed this as completed Sep 15, 2020
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 a pull request may close this issue.

3 participants