Skip to content

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