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

Validating and transcoding conversion functions may return a struct indicating length and success #30

Closed
lemire opened this issue Mar 10, 2021 · 4 comments · Fixed by #157

Comments

@lemire
Copy link
Member

lemire commented Mar 10, 2021

Currently validating conversion functions return a length. This might be better:

struct result {
  bool is_ok;
  size_t length;
}

with structured binding, you can do... auto [is_ok, length] = convert().

@lemire lemire changed the title Validating conversion functions may return a struct. Validating conversion functions may return a struct indicating length and success Mar 20, 2021
@lemire lemire added this to the First public release (0.1) milestone Mar 21, 2021
@WojciechMula
Copy link
Collaborator

I'd see it more like C++ defined for std::from_chars --- struct has a pointer and error code. However, if we want to finally C API and binding to other languages, maybe your idea with plain-old-data is more suitable.

@lemire
Copy link
Member Author

lemire commented May 24, 2021

@WojciechMula Alternatively, you can replace the Boolean with an error code (could be an integer type). Then you want to flip the convention around and have it be error with 0 being ok and any non-zero value representing an error code. It allows you to provide fine error reporting. So...

struct result {
  int error;
  size_t length;
}

but if we are just going to report yes or no, then such an API is a waste of effort and we should go with something simpler.

@lemire
Copy link
Member Author

lemire commented Jul 12, 2022

cc @clausecker

@lemire lemire changed the title Validating conversion functions may return a struct indicating length and success Validating and transcoding conversion functions may return a struct indicating length and success Jul 12, 2022
@lemire
Copy link
Member Author

lemire commented Jul 12, 2022

@NicolasJiaxin This is something you could work on... The scenario of the validation functions is relatively simple. Of course, there are many different design decisions about how to proceed. Benchmarking could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants