Если вы можете использовать библиотеку magic_get :
// requires: C++14, MSVC C++17
#include <iostream>
#include "boost/pfr/precise.hpp"
struct my_struct
{ // no operators defined!
int i;
char c;
double d;
};
bool operator==(const my_struct& l, const my_struct& r)
{
using namespace boost::pfr::ops; // out-of-the-box operators for all PODs!
return boost::pfr::structure_tie( l ) == boost::pfr::structure_tie( r );
}
int main()
{
my_struct s{ 100, 'H', 3.141593 };
my_struct t{ 200, 'X', 1.234567 };
std::cout << ( s == s ) << '\n' << ( s == t ) << "\n";
}
Определяя operator ==
ASSERT_EQ в Google Test, можно использовать:
TEST( Test_magic_get, Test_magic_get )
{
my_struct s{ 100, 'H', 3.141593 };
my_struct t{ 200, 'X', 1.234567 };
//ASSERT_EQ( s, t );
ASSERT_EQ( s, s );
}