C++ Template Basics

Function Templates

Code   Brief Information
type_conversion   Type conversion during argument type deduction. Use of <boost/type_index.hpp>.
return_type_deduction   Three ways to deduce return type in a template functions, differences in C++11, 14, 17


Class Templates

Code   Brief Information
template_entity   What is template entity? – an ordinary function instantiated with a class template.
nonmember_FT   How to declare a template entity? – implicity declaration of new function template
forward_declare_FT   How to declare a template entity? – forward declaration of FT for the class and inside the class declare specialization of nonmember function template


Variadic Templates

Code   Brief Information
example1   Simple recursive print function. Difference in using sizeof...operator with regular if versus compile-time if.


More examples with detailed comments will be added in time.

References




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Exploring Type Erasure as a Design Pattern: A Generic Materials Solver
  • Exploring Policy-Based Design: A Customizable Message Logger in C++
  • GoF Design Patterns: A Brief Overview
  • GPU Practice Codes
  • Just-In-Time Compiled CUDA Kernel