Friday, 20 March 2009

Public Global Operator Functions

I've just added this function to mathlib:

inline Vec4 operator*( float scale, const Vec4 &vec)
return vec * scale;

Can you recognise the need for this function?

I wrote it because I wanted to scale a vector by a float, but didn't want to have the float trailing the vector. Simple really. What's even more simple is that this function doesn't need any special access privileges, and is inlined so it takes up zero time in the linker. If we wrote more functions like this, we'd have cleaner code and lower link times.

No comments: