/cpp_practical_tmp_study

C++ Template Metapogramming Study Resources

Primary LanguageC++

About C++ Template Metaprogramming

Basics Review

  1. C++ Language Features Related to C++ TMP

    1. static_assert: C++11
    2. sizeof
    3. decltype: C++11
    4. template
      1. type template parameter
      2. non-type template parameter
      3. full specialization
      4. partial specialization
      5. template template parameter
      6. variadic template: C++11
    5. using type alias, using type alias template: C++11
    6. variable template: C++14
    7. constexpr: C++11
    8. constexpr if: C++17
    9. user-defined literals: C++11
    10. fold expression: C++17
    11. structured binding: C++17
  2. C++ Library Features Related to C++ TMP

    1. type_traits: C++11
      1. std::integral_constant
      2. std::decay
      3. std::enable_if
      4. std::conditional
      5. std::void_t: C++17
      6. etc.
    2. std::declval: C++11
    3. std::integer_sequence: C++14
    4. std::initializer_list: C++11
    5. std::tuple: C++11
    6. std::variant: C++17
    7. std::optional: C++17

C++ Template Metaprogramming Concept

  1. Meta-function
    1. numeric calculation
    2. type calculation
  2. Meta-function Forwarding
  3. Meta-function Class
  4. SFINAE(Substitution Failure Is Not An Error)

Some Useful C++ Template Metaprogramming Idiom

  1. Overload Resolution Management
  2. Integer Sequence Manipulation

Implementing Some Primitive Metafunctions

  1. identity
  2. type_is
  3. type_list, TL
  4. length
  5. head
  6. tail
  7. last
  8. init
  9. map
  10. filter
  11. foldl, foldr
  12. compose
  13. bind_first, bind_last
  14. reverse
  15. find
  16. unique
  17. ...

Codes and examples of these metafunctions are available at https://github.com/ghjang/skull.

Examples

  1. Member Test
  2. Integer Sequence Generation
  3. make_variant_array function template
  4. Implementing tuple
  5. Implementing Generic Abstract Factory
  6. Aligned Tuple
  7. tuple_cat
  8. ...

References