Real-World Example 2
Learn to use C++ reflection to reflect class members, overload functions, and test capabilities.
Reflection
The term reflection refers to the ability to inspect a class without knowing anything about its contents. In contrast to many other programming languages, C++ does not have built-in reflection, which means we have to write the reflection functionality ourselves. Reflection will be included in future versions of the C++ standard; hopefully, we will see this feature in C++23.
In this example, we are going to limit the reflection to give classes the ability to iterate their members, just like we can iterate the members of a tuple. By using reflection, we can create generic functions for serialization or logging that automatically work with any class. This reduces large amounts of boilerplate code, which is traditionally required for classes in C++.
Making a class reflect its members
Since we need to implement all the reflection functionality ourselves, we will start by exposing the member variables via a function called ...