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 conversion between struct_pack and json without field names #748

Open
romanholidaypancakes opened this issue Aug 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@romanholidaypancakes
Copy link

romanholidaypancakes commented Aug 12, 2024

What happened + What you expected to happen

There are the following structures:

struct person {
  int64_t id;
  std::string name;
  int age;
  double salary;
};

Can be converted to:

[1, "name", 1, 1.333333]

Reproduction way

n/a

Anything else

n/a

Are you willing to submit a PR?

n/a

@qicosmos
Copy link
Collaborator

yes, you can do that:

  person p{32, "tom"};
  auto tp = struct_pack::detail::visit_members(p, [](auto&... args){
    return std::make_tuple(args...);
  });

  std::string s;
  struct_json::to_json(tp, s);

but struct_pack can reflect member names in c++20 after refactor, and the code will be more simpler, you can serialize a struct pack struct to json directly, no need transfer it to a tuple any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants