Testing reflection capabilities

Now we have everything in place:

  • The Town class we will test has a reflect member function returning a tuple of references to its members
  • The equality and less than comparison functions are enabled for all reflectable types
  • The global std::ostream& operator<< is overloaded for reflectable types

Here is a simple test which verifies the functionality:

auto town_tester() {  auto shire = Town{100, 200, "Shire"}; 
  auto mordor = Town{1000, 2000, "Mordor"};   // Prints "100 200 Shire" using reflection  std::cout << shire;   // Prints "1000 2000 Mordor" using reflection  std::cout << mordor;   // Compares mordor and shire using reflection  auto is_same = shire == morder;  assert(!is_same); }

Quite nice, isn't it? With these ...

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.