ClassS04CS141/Comparisons.H

Top | ClassS04CS141 | recent changes | Preferences


#ifndef _COMPARISONS_H
#define _COMPARISONS_H

// default comparison
template <typename T>
int Compare(T const & s, T const & t) {
  if (s > t) return 1;
  if (s < t) return -1;
  return 0;
}

// specialization for char *'s
template <>
int Compare(char * const & a, char * const & b) {
  char * s = a;
  char * t = b;

  while (1) {
    if (*s > *t) return 1;
    if (*s < *t) return -1;
    if (! (*s || *t)) return 0;
    ++s;  ++t;
  }
}


// default equality test
template <typename T>
int Equal(T const &s, T const &t) {
  return Compare(s, t) == 0;
}

#endif

Top | ClassS04CS141 | recent changes | Preferences
This page is read-only | View other revisions
Last edited April 5, 2004 2:58 pm by Neal (diff)
Search: