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_pack] STRUCT_PACK_REFL now support regist private member #399

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

poor-circle
Copy link
Collaborator

@poor-circle poor-circle commented Aug 8, 2023

Why

STRUCT_PACK_REFL can support private memeber

What is changing

  1. remove macro STRUCT_PACK_FREIND_DECL, it's useless now.
  2. macro STRUCT_PACK_REFL can support private memeber.
  3. regist member function in STRUCT_PACK_FREIND_DECL don't need add extra ().

Example

class person : std::vector<int> {
 private:
  int age;

 public:
  std::string name;
  auto operator==(const person& rhs) const {
    return age == rhs.age && name == rhs.name;
  }
  person() = default;
  person(int age, const std::string& name) : age(age), name(name) {}
};
STRUCT_PACK_REFL(person, name, age);
class person {
 private:
  int age_;
  std::string name_;

 public:
  auto operator==(const person& rhs) const {
    return age_ == rhs.age_ && name_ == rhs.name_;
  }
  person() = default;
  person(int age, const std::string& name) : age_(age), name_(name) {}

  int& age() { return age_; };
  const int& age() const { return age_; };
  std::string& name() { return name_; };
  const std::string& name() const { return name_; };
};
STRUCT_PACK_REFL(person, age, name);

@poor-circle poor-circle changed the title [struct_pack] STRUCT_PACK_REFL now support private member [struct_pack] STRUCT_PACK_REFL now support regist private member Aug 8, 2023
@poor-circle
Copy link
Collaborator Author

Due to some bug of clang8-11, this pr can't remove STRUCT_PACK_FRIEND_DECL, i will try to adapt two solve later.

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