So, your solution is to completely replace the fundamental type you use everywhere. |
Your complaint was because NaN and INF are error prone.
If that's the case... then why are you only worried about NaN and INF inside the vector class? If this is a fundamental type that you are using everywhere, then don't have risk having that problem everywhere in your program? Why put a band-aid on just this one area --- an area that has absolutely nothing to do with the actual problem?
And no... my solution is not to replace a fundamental type. My solution is to not worry about such a contrived problem. I have been using doubles for over a decade and have never had a NaN/INF issue.
The point is... you are trying to fix a problem in this vector class... but that vector class has nothing to do with the actual problem.
The compiler will almost always optimize the code to be the same as just directly accessing the members. |
I'm not worried about optimization. I'm worried about the class being overly complicated and clunky to use.
Compare your 33 line class to this, [practically] equally functional and easier to use class:
1 2 3 4 5
|
class Vector2d
{
public:
double x, y;
};
|
The only difference? Doesn't guard against NaN/INF. Which again... is not an issue with vector -- but is an issue with double.
EDIT:
What's more... maybe I
want NaN in my vector!
This is a general purpose support class. It shouldn't be telling me what values are and aren't valid. How can it possibly know what my needs are? I mean... I guess you could make it know... but then it's not a general purpose class anymore -- it's customized class built to address your specific problem.