Could somebody guide me through what gets called in this scenario?
template<class T>
class mat4 {
public :
T matrix[4][4];
mat4();
mat4(vec4<T> i, vec4<T> j, vec4<T> k, vec4<T> t);
mat4(const T input_matrix[4][4]);
//~mat4();
mat4<T> Transposed() const;
void Transpose();
mat4<T> Inversed() const;
void Inverse();
};
With the above code if i call
mat4<float> matrix;
float mf[4][4];
//fill the float matrix here
matrix = mf;
Then i know that the 3rd constructor gets called (it’s not explicit), but what is called beside that? A copy constructor for matrix that takes the temporary object created from the assignment operation? I’m debating whether or not i should create a custom assign operator for it or just let it handle itself. The custom operator would only copy the matrix into the mat4 and return a reference to the mat4, but if there’s no overhead in the automaticly created assignment operator then i’d rather stick to that.
Any decent return value optimization should reduce this to just a call to the third constructor. As long as you’re compiling with optimization, there’s no need to reduce readability to reduce overhead in this case.
Also, I don’t see how a custom copy constructor and/or assignment operator will have less overhead than the compiler-generated ones; they may even complicate the optimization.