Come across this problem once again in the book [*The Modern C++ Challenge*](https://books.google.com/books?id=nl9dDwAAQBAJ&lpg=PP4&dq=modern%20c%2B%2B%20challenge%20epub&pg=PA29#v=onepage&q=modern%20c++%20challenge%20epub&f=false).

> 
> **18. Minimum function with any number of arguments**
> 
> 
> Write a function template that can take any number of arguments and returns the minimum value of them all, using `operator <` for comparison. Write a variant of this function template that can be parameterized with a binary comparison function to use instead of `operator <`.
> 
> 
> 

I wonder how simple and elegant the implementation could be using [c++17](/questions/tagged/c%2b%2b17 "show questions tagged 'c++17'"). The following is the parameterized version. Ideas?

```
#include <algorithm>

template <typename Less, typename T, typename... Ts>
constexpr const T& min(Less less, const T& a, const T& b, const Ts&... rems) {
  if constexpr (sizeof...(rems)) {
    return min(less, std::min(a, b, less), rems...);
  }
  else {
    return std::min(a, b, less);
  }
}

```