Practical Template Meta Programming (Part-1)

Static reflection using Template Meta Programming and Macros

In this blog, we will implement a generic Print(user defined struct) utility function capable of printing all the public members of any user-defined POD struct. For example: // We would like to Print MessageA // which has messageB as member item struct messageA { int a; messageB b; }; // messageB has messageD as member struct messageB { int p; messageD d[3]; }; // struct layout struct messageD { double t; int v; }; and we expect the output as shown below after executing the following program: [Read More]

Cpp chronicle #2

C++ template basics - 1

Template is a great C++ language feature, with which we can make classes and functions operate on generic types without actually writing code for all possible valid types. For example std::vector container in C++11 is a template class. We can use it for with different value types, with the following syntax. std::vector<int> v1; std::vector<char> v2; Here, v1 can hold values of type int and v2 can hold values of type char. [Read More]