Skip to content

Instantly share code, notes, and snippets.

@vladiant
Last active November 19, 2025 18:17
Show Gist options
  • Select an option

  • Save vladiant/0149c8a0283b872f52c23dbf56274d8c to your computer and use it in GitHub Desktop.

Select an option

Save vladiant/0149c8a0283b872f52c23dbf56274d8c to your computer and use it in GitHub Desktop.
C++ Reflection
// https://lemire.me/blog/2025/11/09/automated-equality-checks-in-c-with-reflection-c26/
class person {
public:
person(std::string n, int a) : name(n), age(a) {}
private:
std::string name;
int age;
std::vector<hobby> hobbies;
std::optional<uint64_t> salary;
};
bool compare_same(const T& a, const T& b) {
template for (constexpr auto mem : std::define_static_array(std::meta::nonstatic_data_members_of(^^T, std::meta::access_context::unchecked()))) {
if (!compare_same(a.[:mem:], b.[:mem:])) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment