Skip to content

Instantly share code, notes, and snippets.

@pce
Created September 18, 2020 10:35
Show Gist options
  • Save pce/6ad48480eef444d09f27cfad72d73d36 to your computer and use it in GitHub Desktop.
Save pce/6ad48480eef444d09f27cfad72d73d36 to your computer and use it in GitHub Desktop.
#include <assert.h>
template<typename T>
T Min(T a, T b)
{
return (a < b) ? a : b;
}
// Test
int main() {
assert(Min<double>(3.5,5.0) == 3.5);
assert(Min<int>(4,2) == 2);
// deduction
assert(Min(4,2) == 2);
assert(Min(4.3,2.1) == 2.1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment