Is there a way to have a compile time check, that all members of a class are compared within operator==

I was wondering if there is a way in C++ to have a compile time check, that verifies that all member variables of a class are compared by operator==? And if there is it would also be useful to have a way to explicitly ignore this constaint on some members.

This is useful for my use case in which there is a data structure that is changing over time in our development process, and it happened multiple times already that adjusting the existing operator== was forgotten. This is a silent error which results in a, let’s call it "false positive behaviour", which is hard to find.

Any information is appreciated. Maybe alternative ways to solve the problem, or an explanation to why this compile time check might not be possible.

EDIT: Sadly I am using C++17 and there is no way to update to C++20 in the near future.

Source: Windows Questions C++

LEAVE A COMMENT