In continuation of this topic Variadic template heterogeneous container, I would like to ask the following. Assume, that we have several classes with two members that is dynamic arrays. Now suppose that there is a sequence of objects of these classes, which is packed in heterogeneous container. In this sequence one of arrays-mebers is "output" vector and another array-member is "input" vector, which is pointer to appropriate output array from preceding object. This sequence is implemented as variadic template class:
//Classes, objects which are members of the sequence
template<int NumberElements>
struct A
{
A() : output(new float[NumberElements]){}//allocate output
~A(){delete[] output;}
float *input;//input vector - pointer to output vector from preceding object of sequence
float *output;// output vector (size - NumberElements) of current member of sequence
};
template<int NumberElements>
struct B
{
B() : output(new float[NumberElements]){}//allocate output
~B(){delete[] output;}
float *input;
float *output;
};
template<int NumberElements>
struct C
{
C() : output(new float[NumberElements]){}//allocate output
~C(){delete[] output;}
float *input;
float *output;
};
//Container
template<typename...Arg>
struct HeterogenousContainer
{
HeterogenousContainer();//Do something to setup the sequence
std::tuple<Arg...> elements;
};
How can I properly allocate memory (via new/malloc) for output vectors, and set up input pointers to preceding output vectors? For example, I write next code:
HeterogenousContainer<A<5>, B<7>, C<9>> sequence;
I want that input from first member of sequence to be nullptr, input from second - points to output from first, etc. How to implement it correctly?