vendredi 25 août 2017

Reusing variadic templates for constructors

How can one store a variadic template to enable reuse in later instances?

Code Example:

template <typename T, typename ...initArgs>
Collection_class {

   std::vector<T> storage; 
   initArgs ...constructorArguments;

   Collection_class<T, initArgs>(initArgs... args) {
       constuctorArguments = args;
   }

   void CreateInstance() {
        storage.emplace(constructorArguments); 
   }
}

Is there any way you can store a varidic template as an object/collection that would enable you to reuse it, in this case for a constructor?

I have seen people storing the arguments in a std::tuple however I am unsure how I could use that in a generic class.

Much thanks, JJ.

Aucun commentaire:

Enregistrer un commentaire