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 custom to_chars_float #267

Merged
merged 2 commits into from
Apr 30, 2024
Merged

Conversation

bbbgan
Copy link
Collaborator

@bbbgan bbbgan commented Apr 30, 2024

example:

#include <charconv>  // for to_chars
#include <iostream>  // for std::cout

namespace iguana {

template <typename T>
inline char* to_chars_float(T value, char* buffer) {
  std::cout << "call custom to_chars_float with snprintf\n";
  return buffer + snprintf(buffer, 65, "%g", value);
}

}  // namespace iguana
#include <iguana/json_reader.hpp>
#include <iguana/json_writer.hpp>

struct test_float_t {
  double a;
  float b;
};
REFLECTION(test_float_t, a, b);

void user_defined_tochars_example() {
  test_float_t t{2.011111, 2.54};
  std::string ss;
  iguana::to_json(t, ss);
  std::cout << ss << std::endl;
}
int main(void) {
  user_defined_tochars_example();
  return 0;
}

Copy link
Owner

@qicosmos qicosmos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bbbgan bbbgan merged commit bb724b3 into qicosmos:master Apr 30, 2024
19 of 20 checks passed
@bbbgan bbbgan deleted the to_chars_float branch April 30, 2024 11:33
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

Successfully merging this pull request may close these issues.

2 participants