I'm learning about Variadic Template and Fold Expression. I would like to avoid the use of dynamic allocation and pointers.
To illustrate my problem, I created the Foo (copy and move constructors are deleted) class which inherits from I_Foo.
class I_Foo
{
public:
virtual void Do() = 0;
};
template <int a, int b>
class Foo : public I_Foo
{
public:
explicit Foo(int x) : m_x {x} {}
Foo(const Foo &) = delete;
virtual ~Foo() {}
Foo & operator=(const Foo &) = delete;
protected:
virtual void Do() override { /* Do something */}
private:
static constexpr std::size_t k_ArraySize {a * b};
std::array<int, k_ArraySize> m_Array {};
int m_x;
};
I would like to create a Pool class containing x I_Foo set at compile time but I have no idea how to do that. I'm completely lost. Instantiating the Pool could look like this:
template<typename... Args>
class Pool
{
public:
explicit Pool(Args&&... args) : /* No idea */ {}
private:
Foo1
Foo2
...
FooX
};
Pool<Foo<1,2>, Foo<3,2>> l_t_Pool { Foo<1,2>{1}, Foo<3,2>{2} };
My lack of knowledge does not allow me to know if this is possible. :(