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

[struct_xml, struct_json, struct_yaml][feat]support shared_ptr #402

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

qicosmos
Copy link
Collaborator

@qicosmos qicosmos commented Aug 9, 2023

Why

support smart pointer in struct.

What is changing

Example

struct shared_object {
  std::shared_ptr<std::vector<std::shared_ptr<int>>> vec;
  std::string b;
  std::shared_ptr<int> c;
  std::vector<std::shared_ptr<int>> d;
};
REFLECTION(shared_object, vec, b, c, d);

void test_sp() {
  auto vec = std::make_shared<std::vector<std::shared_ptr<int>>>();
  vec->push_back(std::make_unique<int>(42));
  vec->push_back(std::make_unique<int>(21));
  shared_object contents{std::move(vec),
                         "test",
                         std::make_shared<int>(24),
                         {std::make_shared<int>(1), std::make_shared<int>(4)}};
  std::string str;
  iguana::to_xml(contents, str);

  shared_object cont;
  iguana::from_xml(cont, str);  // throw exception.
  std::cout << cont.b << "\n";
}

@qicosmos qicosmos merged commit a117e76 into alibaba:main Aug 9, 2023
28 checks passed
@qicosmos qicosmos deleted the struct_xxx_support_shared_ptr branch August 9, 2023 02:44
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.

1 participant