fork(2) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <typename Arg1, typename Arg2>
  5. constexpr typename std::common_type<Arg1, Arg2>::type vmin(Arg1&& arg1, Arg2&& arg2)
  6. {
  7. return arg1 < arg2 ? std::forward<Arg1>(arg1) : std::forward<Arg2>(arg2);
  8. }
  9.  
  10. template <typename Arg, typename... Args>
  11. constexpr typename std::common_type<Arg, Args...>::type vmin(Arg&& arg, Args&&... args)
  12. {
  13. return vmin(std::forward<Arg>(arg), vmin(std::forward<Args>(args)...));
  14. }
  15.  
  16. int main()
  17. {
  18. std::cout << vmin(3, 2, 1, 2, 5) << std::endl;
  19. std::cout << vmin(3., 1.2, 1.3, 2., 5.2) << std::endl;
  20. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1
1.2