Template Metaprogramming Practice Codes
Ex. | Code | What I learned? | ||
---|---|---|---|---|
1 | simplest metaprogram with type_traits | How std::is_pointer<T>::value works. How to take template argument T and strip off any pointer if it has one. Compile-time if-else . | ||
2 | dynamic type-dispatch | A dispatch mechanism in C++ to dynamically select and execute type-specific kernel implementations for different scalar types using variadic macros. |
I will add more examples in time.
References
- C++ Templates: The Complete Guide (second ed.) by Vandevoorde, Josuttis, Gregor
- BitsOfQ C++ Template Metaprogramming playlist by Quirijn
- Template Metaprogramming (part 1 & 2) in CppCon by Jody Hagins
Enjoy Reading This Article?
Here are some more articles you might like to read next: