Using the reflection

Now that the Town class has the ability to reflect its member variables, we can automate the creation of bulk functionality which would otherwise require us to retype every member variable. As you know, C++ automatically generates constructors and assignment operators, but other common operators, such as equality (operator==) and less than (operator<) are required to be implemented by the programmer.

class Town { 
  ... 
  auto operator==(const Town& t) const {return reflect()==t.reflect();}
  auto operator<(const Town& t) const {return reflect()<t.reflect();}
  ... 
}; 

In addition to member functions, another bulk function in C++ is to print its content to a stream in order to print its content to a file, or more commonly, log ...

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.