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

Support for constraint environment #254

Closed
elazarl opened this issue Dec 28, 2015 · 2 comments
Closed

Support for constraint environment #254

elazarl opened this issue Dec 28, 2015 · 2 comments

Comments

@elazarl
Copy link

elazarl commented Dec 28, 2015

Hi,

cppformat is a breath of fresh air, especially when you use it for embedded device where stupid errors could be costly.

Do you plan to make a subset of cppformat available for more constraint environment?

Specifically:

  1. Ability to turn off POSIX error handling. I don't have stderr, I only have serial.
  2. Ability to turn off classes that requires dynamic memory allocation - stack based alternative for MemoryWriter, and ability to turn off support for basic_string.
  3. Ability to turn off wchar support, which is not always available, and not always cost-effective to implement.
  4. Ability to use custom printing function, without requiring user to take all the c++ streams abstraction.

Would you accept pull requests in this direction?

@vitaut
Copy link
Contributor

vitaut commented Dec 29, 2015

Hi,

Thank you for the nice feedback.

Do you plan to make a subset of cppformat available for more constraint environment?

No, I don't have any plans specifically targeting constrained environments.

[1] Ability to turn off POSIX error handling. I don't have stderr, I only have serial.

I'm not sure what you mean by that. The errors are reported as exceptions, but you can provide your own error handling mechanism via FMT_THROW.

[2] Ability to turn off classes that requires dynamic memory allocation - stack based alternative for MemoryWriter, and ability to turn off support for basic_string.

I think turning off classes with dynamic memory allocation completely via conditional compilation will be too messy, but writing to a fixed, possibly stack-allocated, array is already supported:

char buffer[100];
fmt::ArrayWriter w(buffer);
w.write("The answer is {}", 42);

This could be wrapped in a function for even easier use:

char buffer[100];
format_array(buffer, "The answer is {}", 42);

[3] Ability to turn off wchar support, which is not always available, and not always cost-effective to implement.

Again, I think it would be too messy to turn off completely, but it doesn't add any overhead if you don't use it.

[4] Ability to use custom printing function, without requiring user to take all the c++ streams abstraction.

IOStreams are already optional and only used when formatting types that provide an overloaded ostream operator<<. You can provide a custom formatting function by overloading format instead:

void format(Formatter &f, const char *&format_str, const MyType &value) {
  // parse format_str and format value
}

I'm also open to pull requests that improve support for such environments provided that they don't obscure the code by introducing a lot of conditional compilation or similar. If you have any specific ideas, I recommend discussing them here or in separate issues before preparing a full PR (although a small prototype to demonstrate the idea might be useful).

@vitaut
Copy link
Contributor

vitaut commented Dec 30, 2015

I'm closing this for now, but feel free to reopen or open another issue to discuss any specific suggestion in more details.

@vitaut vitaut closed this as completed Dec 30, 2015
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