RE: Latest commits
Posted by Jens Thiel-2 on Jul 23, 2003; 4:41am
URL: http://quantlib.414.s1.nabble.com/Latest-commits-tp10269p10276.html
Hi there,
one idea here: implement < and > for the cases were it is well defined, and
expand == to be "not larger and not smaller", eg.
4w<1m false
4w>1m false
4w==1m expands to ( !(4w<1m) && !(4w>1m) ) which is true
28d<1m false
31d>1m false
30d==1m expands to ( !(30d<1m) && !(30d>1m) ) which is true
This could also be done in a Compare() function that returns either -1, 0 or
1 to make sure that absolutely noone uses the operators carelessly.
Regards,
Jens.
c) Maybe Period::operator== should be a partial function. There's a subset
of the domain where it is well defined ("1 year == 12 months" is ok, and so
is "3 days == 3 days" and "14 days == 2 weeks") but how about "31 days == 1
month"? Or "4 weeks == 1 month"? With the current implementation, the first
is false, with the disconcerting result that if d = Date(22,7,2003), p1 !=
p2 but d.plus(p1) == d.plus(p2). The second is true, but for most dates,
d.plus(p1) != d.plus(p2). How about throwing an exception if the == is
undecidable?