-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
format_to() with fmt::memory_buffer docs vague #877
Comments
Found more unexpected behavior.
Produces: "hello_again" The following code is executed to produce the output.
Since copy_n() does not explicitly extend the size of the out container, the rest is clipped. Should I expect what actually happens, or should I expect the buffer to be lengthened? |
This is unsafe if fmt::format_to(x.begin(), "hello_again_world!");
Neither. The buffer is not lengthened (because in general you can't increase the buffer size from an iterator) and the output won't necessarily be truncated. Your second example has a UB and |
And I clarified the append behavior in 66992e9. |
Thanks for the clarification. In retrospect, it is obvious that iterators should not be expected to lengthen a buffer. |
First off, great library! Would love to see it as part of the stdlib.
When passing a fmt::memory_buffer as the first argument in format_to(), it is wrapped in a back_inserter_iterator. It would be helpful if there was a notation in the documentation that explained this relationship. I have read through the docs a few times and it was unclear to me if format_to() would overwrite or append. Through experimentation I discovered that it appended.
From what I can tell, appending appears to be the "standard" behavior, but it does not appear to be required behavior. I feel like it deserves a notation indicating this fact.
Thanks!
The text was updated successfully, but these errors were encountered: