ClassS04CS141/Comparisons.H

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences

No diff available--this is the first major revision. (no other diffs)

#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

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