Evaluating the assembler output of the reflection

To ensure that we do not lose any runtime performance, let's compare the assembler output of our Town class with an equal class where the operator== operator has been handcrafted like this:

auto operator==(const Town& t) const { 
  return  
    houses_ == t.houses_ && 
    settlers_ == t.settlers_ && 
    name_ == t.name_; 
}

Then, we create a simple function which takes two towns as references and returns the result of the comparison:

auto compare_towns(const Town& t0, const Town& t1) {   return t0 == t1; } 

Inspecting the generated assembler output (in this case from GCC 6.3 with optimization level 3), we see that the generated assembler is exactly the same:

Handcrafted operators and reflected operators results ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.