Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

constructing tuple of classes type from template argument types

I would like to construct a type which is a tuple of same class with different template argument types. I mean:

Imagine we have a class

template<class Arg>
class A
{
    //.... details
}

I want to define something like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

template<class... Args>
struct construct_tuple 
{
    //assume I can access Args[...]
    using type = std::tuple<A<Args[0]>, A<Args[1]>, ..., A<Args[n]>>;
}

Could you please help?

I believe there might be a solution by iterating over the variadic arguments and using conctenation between tuple types or maybe using some other TMP e.g. std::enable_if or std::conditional_t.

>Solution :

While your code doesn’t try to construct anything, this will compile and provide what you want.

template<class... Args>
struct construct_tuple 
{
    //assume I can access Args[...]
    using type = std::tuple<A<Args>...>;
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading