General Purpose library for Freestanding C++ and POSIX systems
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

47 rindas
735 B

  1. #pragma once
  2. namespace gp{
  3. template<typename T, typename U, typename ...rest>
  4. constexpr T max(T first, U second, rest... args)
  5. {
  6. if constexpr (sizeof...(args) == 0)
  7. {
  8. return first > second ? first : second;
  9. }
  10. else
  11. {
  12. return max(first > second ? first : second, args...);
  13. }
  14. }
  15. template<typename T, typename U, typename ...rest>
  16. constexpr T min(T first, U second, rest... args)
  17. {
  18. if constexpr (sizeof...(args) == 0)
  19. {
  20. return first < second ? first : second;
  21. }
  22. else
  23. {
  24. return min(first < second ? first : second, args...);
  25. }
  26. }
  27. template<typename T>
  28. constexpr T clamp(T first, T value, T last)
  29. {
  30. if(value < first) return first;
  31. if(value > last) return last;
  32. return value;
  33. }
  34. }