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

Non-throwing version of basic_fixed_buffer #915

Closed
oktal opened this issue Oct 24, 2018 · 1 comment
Closed

Non-throwing version of basic_fixed_buffer #915

oktal opened this issue Oct 24, 2018 · 1 comment

Comments

@oktal
Copy link

oktal commented Oct 24, 2018

I would like to use fmt::basic_fixed_buffer<CharT> in combination with fmt::writer to format content in a fixed-size buffer.

However, I would like to keep formatting until I reach the capacity of the buffer and be notified when it happens. Currently, I'm relying on the fact that basic_fixed_buffer::grow() throws a std::runtime_error to know whether my buffer is full or not but I think it's not ideal.

I propose non-throwing version of grow() and write functions. For example, I'd like to write:

char buffer[MAX_BODY_SIZE];
fmt::basic_fixed_buffer<char> buf(buffer);
fmt::writer writer(buf);

if (!writer.try_write(sequence_number))
{
    // Do something
}

Thanks.

@vitaut
Copy link
Contributor

vitaut commented Oct 25, 2018

basic_fixed_buffer was an artefact of a legacy API and was removed in #902. Please use the format API instead, e.g.

fmt::format_to_n(buffer, MAX_BODY_SIZE, "{}", sequence_number);

@vitaut vitaut closed this as completed Oct 25, 2018
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

2 participants