Boost logo

Boost :

From: Ben Young (ben.young_at_[hidden])
Date: 2002-11-25 09:12:45


Recently at our company we had a couple of bugs relating to people
incorrectly writing comparison operators, so I came up with this little
helper. It is very trivial, but useful none the less as bogus comparison
operators can be the cause of many bugs.

Obviously it could be improved to take a predictate of some kind and
checged to use the boost pre-processor library, but, otherwise, is anyone
interested

Yours

Ben Young
--- -----

template<class T1>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1)
{
  return lhs1 < rhs1;
}

template<class T1, class T2>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2);
}

template<class T1, class T2, class T3>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3);
}

template<class T1, class T2, class T3, class T4>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3,
                          const T4& lhs4, const T4& rhs4)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3,
                                   lhs4, rhs4);
}

template<class T1, class T2, class T3, class T4, class T5>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3,
                          const T4& lhs4, const T4& rhs4,
                          const T5& lhs5, const T5& rhs5)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3,
                                   lhs4, rhs4,
                                   lhs5, rhs5);
}

template<class T1, class T2, class T3, class T4, class T5, class T6>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3,
                          const T4& lhs4, const T4& rhs4,
                          const T5& lhs5, const T5& rhs5,
                          const T6& lhs5, const T6& rhs5)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3,
                                   lhs4, rhs4,
                                   lhs5, rhs5,
                                   lhs6, rhs6);
}

template<class T1, class T2, class T3, class T4, class T5, class T6, class
T7>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3,
                          const T4& lhs4, const T4& rhs4,
                          const T5& lhs5, const T5& rhs5,
                          const T6& lhs6, const T6& rhs6,
                          const T7& lhs7, const T7& rhs7)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3,
                                   lhs4, rhs4,
                                   lhs5, rhs5,
                                   lhs6, rhs6,
                                   lhs7, rhs7);
}

template<class T1, class T2, class T3, class T4, class T5, class T6, class
T7, class T8>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3,
                          const T4& lhs4, const T4& rhs4,
                          const T5& lhs5, const T5& rhs5,
                          const T6& lhs6, const T6& rhs6,
                          const T7& lhs7, const T7& rhs7,
                          const T8& lhs8, const T8& rhs8)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3,
                                   lhs4, rhs4,
                                   lhs5, rhs5,
                                   lhs6, rhs6,
                                   lhs7, rhs7,
                                   lhs8, rhs8);
}

template<class T1, class T2, class T3, class T4, class T5, class T6, class
T7, class T8, class T9>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3,
                          const T4& lhs4, const T4& rhs4,
                          const T5& lhs5, const T5& rhs5,
                          const T6& lhs6, const T6& rhs6,
                          const T7& lhs7, const T7& rhs7,
                          const T8& lhs8, const T8& rhs8,
                          const T9& lhs9, const T9& rhs9)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3,
                                   lhs4, rhs4,
                                   lhs5, rhs5,
                                   lhs6, rhs6,
                                   lhs7, rhs7,
                                   lhs8, rhs8,
                                   lhs9, rhs9);
}

template<class T1, class T2, class T3, class T4, class T5, class T6, class
T7, class T8, class T9, class T10>
bool strict_weak_ordering(const T1& lhs1, const T1& rhs1,
                          const T2& lhs2, const T2& rhs2,
                          const T3& lhs3, const T3& rhs3,
                          const T4& lhs4, const T4& rhs4,
                          const T5& lhs5, const T5& rhs5,
                          const T6& lhs6, const T6& rhs6,
                          const T7& lhs7, const T7& rhs7,
                          const T8& lhs8, const T8& rhs8,
                          const T9& lhs9, const T9& rhs9,
                          const T10& lhs10, const T10& rhs10)
{
  if(lhs1 < rhs1) return true;
  else if(rhs1 < lhs1) return false;
  else return strict_weak_ordering(lhs2, rhs2,
                                   lhs3, rhs3,
                                   lhs4, rhs4,
                                   lhs5, rhs5,
                                   lhs6, rhs6,
                                   lhs7, rhs7,
                                   lhs8, rhs8,
                                   lhs9, rhs9,
                                   lhs10, rhs10);
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk