Something like this:
template <typename Type>
class MyMatrixRow
{
public:
MyMatrixRow(Type column1, Type column2, Type column3) :
column1(column1), column2(column2), column3(column3) { }
Type column1, column2, column3;
};
template <typename Type>
class MyMatrix
{
public:
MyMatrixRow(MyMatrixRow<Type> row1, MyMatrixRow<Type> row2, MyMatrixRow<Type> row3)
{
data.resize(9);
data[0] = row1.column1;
data[1] = row1.column2;
data[2] = row1.column3;
data[3] = row2.column1;
data[4] = row2.column2;
data[5] = row2.column3;
data[6] = row3.column1;
data[7] = row3.column2;
data[8] = row3.column3;
}
private:
std::vector<Type> data;
};The structs passed in to the constructor are just used for constructing and then discarded.
The code:
MyMatrix<float> matrix = {{0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f}};Actually turns into:
MyMatrix<float> matrix(MyMatrixRow<float>(0.0f, 0.0f, 0.0f),
MyMatrixRow<float>(0.0f, 0.0f, 0.0f),
MyMatrixRow<float>(0.0f, 0.0f, 0.0f));...and hopefully the entire MyMatrixRow() thing would be compiled out, but I don't know anything about compiler optimizing so I can't say for sure.