January 2018
Intermediate to advanced
374 pages
9h 53m
English
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:
Read now
Unlock full access