/*
* Copyright ©2026 Soham Pardeshi. All rights reserved.
* Permission is hereby granted to students registered for University of
* Washington CSE 333 for use solely during Summer Quarter 2026 for
* purposes of the course. No other use, copying, distribution, or
* modification is permitted without prior written consent. Copyrights
* for third-party components of this work must be honored. Instructors
* interested in reusing these course materials should contact the author.
*/
#ifndef COMPARE_H_
#define COMPARE_H_
// A function template: the same function written once, for any type T that
// supports operator<. See lecture 12 slides 37-42.
//
// Google style (and CSE 333) puts the full template DEFINITION in the
// header, because the compiler must see the body to generate code for each
// concrete type it is used with (slide 42).
template <typename T>
int compare(const T& a, const T& b) {
if (a < b) return -1;
if (b < a) return 1;
return 0;
}
// Returns the smaller of a and b. Note both parameters are T, so a call
// like smaller(3, 2.5) is an error: the two arguments disagree on T.
template <typename T>
T smaller(T a, T b) {
return (a < b) ? a : b;
}
#endif // COMPARE_H_