El 21/10/2016 a las 23:43, Rahman Salim Zengin escribió:
Hi,
The code in question is a simple chained comparison implementation. It works with any type If relational operators for that type is defined.
https://github.com/rszengin/chain
May some people find it useful?
I think this can be further evolved to be useful. A couple of comments: * Seconding Edward's answer, using operator < to initiate the comparison chain cmp::chain < 0 < x <= 5 looks arbitrary. Maybe operator << cmp::chain << 0 < x <= 5 or something even less smart cmp::chain{0} < x <= 5 is better. * As it stands, you're not detecting foul-smelling comparisons such as cmp::chain < x <= y >= z // not exactly wrong, but not the mathematical custom or (more importantly) cmp::chain < 5 <= y <= 0 // always false The first can be made not to compile by making Comparator::operator< (and <=) return a type different than and incompatible with the type returned by Comparator::operator> (and >=). As for the second I *think* it can be detected with some constexpr machinery. Joaquín M López Muñoz