I am making a small helper class that derives from std::array
. The constructor does not inherit, obviously, and it is that which is responsible for brace-initialization; for example:
template<typename T, size_t size>
struct foo : std::array<T,size>
{
foo(int a, int b)
: std::array<T,size>{a,b}
{
//nothing goes here since constructor is just a dummy that
//forwards all arguments to std::array constructor
}
}
int main()
{
foo<int,2> myobj = {1,2}; //brace initialization calls custom constructor with inner elements as arguments
}
The amount of arguments has to match exactly, so I am leaning towards using something like a variadic function argument in the constructor (since I am not only going to be using 2 elements in the array every single time). Using this, how would I forward the variadic argument pack to the std::array
constructor? I am open to other methods of brace initialization that allow forwarding to the std::array
constructor.
Note: std::initializer_list
requires runtime initialization, and i am looking for a compile time/constexpr compatible method. Thank you.