title: Can a "future-safe" compare operator be crafted in C++?
body: <p>Greetings all,</p>
  
  <p>Is it possible to craft a future-safe comparison operator (==) in C++?</p>
  
  <p>The problem I faced was that we have a class with multiple members. We have a comparison operator to validate if instance-1 of the object has the same values as instance-2.</p>
  
  <p>i.e. we can do</p>
  
  <pre><code>class blarg {
      .....
  };
  
  .....
  
  blarg   b1(..initializers...);
  blarg   b2 = b1;
  
  if (b1 == b2) {
      ... then do something ....
  }
  </code></pre>
  
  <p>However, I had a co-worker that added a new member to the class, but failed to update the comparison operator. This lead to problems that took a while for us to figure out.</p>
  
  <p>Is there a coding practice, I mean <strong><em>other</em></strong> than code review (that failed for us), or coding method, design, template, magic beans, whatever that could help avoid situations like this?</p>
  
  <p>My first reaction was to use the <code>memcmp</code> command. However, after reading the stack overflow entry for "<a href="https://stackoverflow.com/questions/1020820/comparing-structures-in-c-vs-c">Comparing structures in C vs C++</a>" I see that this can be problematic due to C++ classes having more than just the member data inside.</p>
  
  <p>How do others deal with this? </p>
  
  <p>Thank you in advance for your help.</p>