Bitwise comparison of any structure What I tried to do is compare arbitrary structures independent of the == operator implementation.

template&lt;typename T&gt;
bool bitWiseCompare(T a, T b)
{
  size_t size = sizeof(T) / sizeof(char);
  char* array_a = (char*)(&amp;a);
  char* array_b = (char*)(&amp;b);
  for(size_t i = 0; i&lt;size; i++)
  {
    if(array_a[i] != array_b[i])
    {
      return false;
    }
  }
  return true;
}
This comparison can fail if there are any padding bytes within T, as those extra bytes are not initialized to any particular value.

Another source of failure can come from inheritance.  If one of the objects is part of a larger class (T is being used as a base class) with virtual functions, the vtable pointers can be different if a and b are part of different class hierarchies.  Virtual inheritance of base classes of T can also cause problems.

sizeof(char) is always 1, so there is no need to divide by it.

Since you're only reading from your parameters, you should take them by const &amp;T to avoid making unnecessary copies.