Created
March 3, 2021 15:40
-
-
Save pdimov/35bd34dab981667777ff6433818e8768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/describe.hpp> | |
#include <boost/mp11.hpp> | |
#include <vector> | |
#include <variant> | |
using namespace boost::describe; | |
namespace app | |
{ | |
template<class T, | |
class Bd = describe_bases<T, mod_any_access>, | |
class Md = describe_members<T, mod_any_access>> | |
bool operator==( T const& t1, T const& t2 ) | |
{ | |
bool r = true; | |
boost::mp11::mp_for_each<Bd>([&](auto D){ | |
using B = typename decltype(D)::type; | |
r = r && (B const&)t1 == (B const&)t2; | |
}); | |
boost::mp11::mp_for_each<Md>([&](auto D){ | |
r = r && t1.*D.pointer == t2.*D.pointer; | |
}); | |
return r; | |
} | |
struct A | |
{ | |
int x = 1; | |
}; | |
BOOST_DESCRIBE_STRUCT(A, (), (x)) | |
struct B | |
{ | |
int y = 2; | |
}; | |
BOOST_DESCRIBE_STRUCT(B, (), (y)) | |
struct C | |
{ | |
std::vector<std::variant<A, B>> v; | |
}; | |
BOOST_DESCRIBE_STRUCT(C, (), (v)) | |
} // namespace app | |
#include <iostream> | |
int main() | |
{ | |
app::C c1, c2, c3{{ {} }}; | |
std::cout << ( c1 == c2 ) << ' ' << ( c1 == c3 ) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment