Search code examples
c++c-preprocessorc++20variadic-macrosfold-expression

C++20: generate type from given variadic types


Lets say, I have a variadic type list which can grow e.g.

#define MY_TYPES  void, float, int, vector<long>, ..... 

I am looking for way to generate these type definition at compile time in c++17/20 in generic way, e.g.

#define to_tuple(MY_TYPES) ==> std::tuple<future<void>, future<float>, future<int>....>
using tupleType = decltype(to_tuple<ALL_TYPES>); // this can be then used in struct as a member.

struct foo {
   ...
   ...
   tupleType tups;
}

or, alternatively if this can be done using template metaprogramming ?

Thanks for the help.


Solution

  • template <typename ...P>
    using tuple_of_futures_t = std::tuple<std::future<P>...>;
    
    using X = tuple_of_futures_t<void, float, int, std::vector<long>>;