Home - acolomitchi/MPinCPP GitHub Wiki

Metaprogramming using C++ templates

  1. Template type variadic pack transformation - the com::caffeineowl::arg_pack_trn template
    File: arg_pack_trn.hpp
    Takes a variadic destination template and a transform (also variadic) one and returns a type defined as the destination parametrized with all the types resulted by applying the transformation
    More details in here
  2. Type replacing - the com::caffeineowl::replace_type template
    File: replace_type.hpp
    Implements the exercise 2.1 in "C++ Template Metaprogramming" with a C++11 syntax and using variadic template parameters.
Write a ternary metafunction `replace_type<c,x,y>` that takes an arbitrary compound type `c` as its first parameter, and replaces all occurrences of a type `x` within `c` with `y`:
  typedef replace_type< void*, void, int >::type t1; // int*

typedef replace_type< int const*[10] , int const , long

::type t2; // long* [10]

typedef replace_type< char& (*)(char&) , char& , long&

::type t3; // long& (*)(long&)

You can limit the function types you operate on to those with fewer than two arguments.
Unlike the original problem, the challenge was to make `replace_type` template handle type replacement in functions with arbitrary numbers of parameters - of course it uses [`arg_pack_trn`](#arg_pack_trn).
⚠️ **GitHub.com Fallback** ⚠️