C++ Class members specified by template

Refresh

February 2019

Views

36 time

1

Is it possible to use a variadic template to specify the members of a class? An acceptable solution would involve storing the data internally in a tuple.

template <typename ... Args> 
struct FromPP {
     // TODO: Get the tuple type from parameter pack
     std::tuple<> data;    
     // TODO: write the constructors

     // Other code... E.g. A print method, and manipulations with 
     // other points of the same type... 
}

I would ideally like some implementation that has both default and copy constructors:

FromPP<float>();    // decltype(data) == std::tuple<float>
FromPP<float>(1.1); // decltype(data) == std::tuple<float>

FromPP<float,int>();       // decltype(data) == std::tuple<float,int>
FromPP<float,int>(1.1, 5); // decltype(data) == std::tuple<float,int>

etc.

If possible, I would like a C++11 solution. Some hardware we use has spotty C++14 support.

0 answers