On Apr 3, 2005 5:08 AM, Jedediah Smith
I need a type equivelant to rational<int> but supporting two special values, +inf and -inf which compare greater and less (respectively) to all other values besides themselves. I don't need to perform any arithmetic on the inf values so those operations can be undefined.
What is the best strategy for creating such a type? Would it be better to subclass rational or create an underlying integer type with the inf values and use rational based on that underlying type? If the former option, how exactly would I do it?
I expect that subclassing wouldn't be a good idea since none of the critical functions are virtual ( for good -- speed -- reason ). The way that immediatly jumps to mind is copying rational<> and changing it to allow a zero denominator to represent infinities, although this violates OnceAndOnlyOnce, so perhaps a class that has a rational as a member would be a more maintainable option, but I expect it would be to run and more annoying to code. A with_inf<> wrapper for a numeric type seems to me to be the best option as it would be straight-foreward and usable in other contexts. The only problems I see with that is your denominator would also get overhead from checking for infs ( when it should never have them ) and that there's no simple way for a rational< with_inf<> > divide-by-zero to return the appropriate +/- inf value. - Scott McMurray