Skip to content

Instantly share code, notes, and snippets.

@FrankHB
Last active December 17, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankHB/5546146 to your computer and use it in GitHub Desktop.
Save FrankHB/5546146 to your computer and use it in GitHub Desktop.
A set of "max" templates using parameter pack.
#include <string>
#include <iostream>
using namespace std;
template<typename T>
inline const T&
max_xx(const T& x, const T& y)
{
return y < x ? x : y;
}
template<typename T, typename... P>
inline const T&
max_xx(const T& x, const T& y, const P& ... args)
{
return max_xx(max_xx(x, y), args...);
}
int main()
{
cout << max_xx(string("abc"), string("xxx"), string("defz")) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment