utility.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2024 Matt Borland
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_TOOLS_UTILITY
  6. #define BOOST_MATH_TOOLS_UTILITY
  7. #include <boost/math/tools/config.hpp>
  8. #ifndef BOOST_MATH_HAS_GPU_SUPPORT
  9. #include <utility>
  10. namespace boost {
  11. namespace math {
  12. template <typename T>
  13. constexpr T min BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b)
  14. {
  15. return (std::min)(a, b);
  16. }
  17. template <typename T>
  18. constexpr T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b)
  19. {
  20. return (std::max)(a, b);
  21. }
  22. template <typename T>
  23. void swap BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (T& a, T& b)
  24. {
  25. return (std::swap)(a, b);
  26. }
  27. } // namespace math
  28. } // namespace boost
  29. #else
  30. namespace boost {
  31. namespace math {
  32. template <typename T>
  33. BOOST_MATH_GPU_ENABLED constexpr T min BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b)
  34. {
  35. return a < b ? a : b;
  36. }
  37. template <typename T>
  38. BOOST_MATH_GPU_ENABLED constexpr T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b)
  39. {
  40. return a > b ? a : b;
  41. }
  42. template <typename T>
  43. BOOST_MATH_GPU_ENABLED constexpr void swap BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (T& a, T& b)
  44. {
  45. T t(a);
  46. a = b;
  47. b = t;
  48. }
  49. } // namespace math
  50. } // namespace boost
  51. #endif // BOOST_MATH_HAS_GPU_SUPPORT
  52. #endif // BOOST_MATH_TOOLS_UTILITY