| 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 |
|
| 6 |
#ifndef BOOST_MATH_TOOLS_UTILITY |
| 7 |
#define BOOST_MATH_TOOLS_UTILITY |
| 8 |
|
| 9 |
#include <boost/math/tools/config.hpp> |
| 10 |
|
| 11 |
#ifndef BOOST_MATH_HAS_GPU_SUPPORT |
| 12 |
|
| 13 |
#include <utility> |
| 14 |
|
| 15 |
namespace boost { |
| 16 |
namespace math { |
| 17 |
|
| 18 |
template <typename T> |
| 19 |
constexpr T min BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b) |
| 20 |
{ |
| 21 |
return (std::min)(a, b); |
| 22 |
} |
| 23 |
|
| 24 |
template <typename T> |
| 25 |
constexpr T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b) |
| 26 |
{ |
| 27 |
return (std::max)(a, b); |
| 28 |
} |
| 29 |
|
| 30 |
template <typename T> |
| 31 |
void swap BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (T& a, T& b) |
| 32 |
{ |
| 33 |
return (std::swap)(a, b); |
| 34 |
} |
| 35 |
|
| 36 |
} // namespace math |
| 37 |
} // namespace boost |
| 38 |
|
| 39 |
#else |
| 40 |
|
| 41 |
namespace boost { |
| 42 |
namespace math { |
| 43 |
|
| 44 |
template <typename T> |
| 45 |
BOOST_MATH_GPU_ENABLED constexpr T min BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b) |
| 46 |
{ |
| 47 |
return a < b ? a : b; |
| 48 |
} |
| 49 |
|
| 50 |
template <typename T> |
| 51 |
BOOST_MATH_GPU_ENABLED constexpr T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (const T& a, const T& b) |
| 52 |
{ |
| 53 |
return a > b ? a : b; |
| 54 |
} |
| 55 |
|
| 56 |
template <typename T> |
| 57 |
BOOST_MATH_GPU_ENABLED constexpr void swap BOOST_MATH_PREVENT_MACRO_SUBSTITUTION (T& a, T& b) |
| 58 |
{ |
| 59 |
T t(a); |
| 60 |
a = b; |
| 61 |
b = t; |
| 62 |
} |
| 63 |
|
| 64 |
} // namespace math |
| 65 |
} // namespace boost |
| 66 |
|
| 67 |
#endif // BOOST_MATH_HAS_GPU_SUPPORT |
| 68 |
|
| 69 |
#endif // BOOST_MATH_TOOLS_UTILITY |