how to write a c++ template that gives the maximum of two args?
c++, max, templates
Solution
template <int x, int y>
struct myMax
{
static const int value = (x > y) ? x : y;
};
If you are going to be using it only with sizes, you can use `std::size_t` instead of `int`.
Problem
Both arguments are guaranteed to be integers. How do I write myMax such that: ``` myMax<1, 2>; // 2 myMax<3, 2>; // 3 ? ``` I want this to be evaluated at compile time, not run time. (Need to then use this with sizeof for a typelist to allocate space for a variant.) Thanks!