Joe Smith
Joe Smith

Reputation: 3

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.

Upvotes: 0

Views: 78

Answers (1)

HolyBlackCat
HolyBlackCat

Reputation: 96941

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>>;

Upvotes: 4

Related Questions