challenge: implement the max function

Donth Ave d at onth.ave
Tue Jan 23 08:37:45 PST 2007


== Quote from Andrei Alexandrescu:

> T2.max > T1.max
> true ? T1 : T2
>      if (rhs > lhs) return rhs;

According to the generality of the challenge you have to admit at least
one of the following:
1) On posting the challenge some of the available properties of the
possible operands where silently dropped
2) The sample solution does not solve the challenge.

This is because in the challenge it is not required that
a1) all involved types have a maximum at all
a2) all involved types have the .max-property
b) all involved types are implicitely convertible to each other
c1) all involved values are totally ordered
c2) none of the storageclasses is "lazy"

Reason:
Violations of a1) or a2) might break "T2.max > T1.max"
Violations of b) might break "true ? T1 : T2"
Violations of c1) might break "rhs > lhs"
Violations of c2) might break "if (rhs > lhs) return rhs;" because this implies
one more evaluation.


Furthermore the implicite requirement of the max-function is also
violated, which is to be usable as an rvalue.

This is because in the challenge it is not required that
d) none of the involved types is a class.

Reason:
If the types include classes as well as basic types, then it is not clear which
one will be returned, but classes will need their opCast to be called, which might
break "return rhs"
--
Anonymity is not a Crime



More information about the Digitalmars-d mailing list