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

problems using FMT_COMPILE with fmt::memory_buffer #1771

Closed
jeffreylu9 opened this issue Jul 13, 2020 · 5 comments
Closed

problems using FMT_COMPILE with fmt::memory_buffer #1771

jeffreylu9 opened this issue Jul 13, 2020 · 5 comments

Comments

@jeffreylu9
Copy link

It seems like the FMT_COMPILE macro doesn't work with fmt::memory_buffer. Here's an example: https://godbolt.org/z/c4qd38

Separately, I'm also getting a different compilation error when passing a string literal as one of the arguments (see https://godbolt.org/z/z1ofqv). Maybe there's something I'm missing here?

@vitaut
Copy link
Contributor

vitaut commented Jul 14, 2020

format_to taking a memory buffer doesn't support FMT_COMPILE but you can pass an iterator instead:

#include <fmt/compile.h>

int main() {
  std::string s = "foo";
  fmt::memory_buffer buf;
  fmt::format_to(std::back_inserter(buf), FMT_COMPILE("{}"), s);
}

@jeffreylu9
Copy link
Author

Ok, thanks. Are there plans to support this in a future release?

@vitaut
Copy link
Contributor

vitaut commented Jul 14, 2020

Are there plans to support this in a future release?

Yes

@vitaut vitaut closed this as completed Jul 30, 2020
@yamaken93
Copy link

yamaken93 commented Apr 7, 2021

@vitaut is using format_to with std::back_inserter and FMT_COMPILE faster than using format_to without std::back_inserter and without FMT_COMPILE? I have found in tests that its faster with std::back_inserter, its like the FMT_COMPILE compensates the std::back_inserter "overhead"(as far i understood, it insert byte per byte in the buffer). I asked here to prevent a new issue creation.

@vitaut
Copy link
Contributor

vitaut commented Apr 7, 2021

FMT_COMPILE is usually faster than runtime format string processing. Writing via back_inserter should be roughly the same as writing to buffer directly but I haven't checked.

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