lundi 24 octobre 2016

use the TYPE from the tempate type argument list

I would like to use the type information from a class template argument list.

Working example with quick workaround:

struct NoParam {};
template< typename A = NoParam,
          typename B = NoParam,
          typename C = NoParam,
          typename D = NoParam,
          typename E = NoParam,
          typename F = NoParam >
struct TypeList
{
  typedef A T1;
  typedef B T2;
  typedef C T3;
  typedef D T4;
  typedef E T5;
  typedef F T6;
};

template<typename... Types>
class Application
{
   Application()
   {
      // the actual code will store the created instances in a tuple or map..
      std::make_unique< TypeList<Types...>::T1 > ();
      std::make_unique< TypeList<Types...>::T2 > ();
      std::make_unique< TypeList<Types...>::T3 > ();
      std::make_unique< TypeList<Types...>::T4 > ();
      std::make_unique< TypeList<Types...>::T5 > ();
      std::make_unique< TypeList<Types...>::T6 > ();
   }
}

Is there any generic way...

  • to iterate over Types and get the type info (for creating instances)
  • no hard coded for only limited 6 types in the example

Aucun commentaire:

Enregistrer un commentaire