0

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.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
Joe Smith
  • 3
  • 1
  • Please [avoid macros like a fire](https://stackoverflow.com/a/14041847/1387438). There is some cases there is no choice, but they are quite rare and it is not your case. – Marek R Jan 29 '21 at 17:55

1 Answers1

4
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>>;
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207