1 | #pragma once |
2 | |
3 | #include <type_traits> |
4 | #include <algorithm> |
5 | #include <cmath> |
6 | |
7 | namespace mbgl { |
8 | namespace util { |
9 | |
10 | template <typename T> |
11 | typename std::enable_if_t<std::is_integral<T>::value, T> max(T a, T b) { |
12 | return std::max(a, b); |
13 | } |
14 | |
15 | template <typename T> |
16 | typename std::enable_if_t<std::is_floating_point<T>::value, T> max(T a, T b) { |
17 | return ::fmax(x: a, y: b); |
18 | } |
19 | |
20 | template <typename T, typename... Ts> |
21 | typename std::enable_if_t<std::is_arithmetic<T>::value, T> max(T a, T b, Ts... args) { |
22 | return max(a, max(b, args...)); |
23 | } |
24 | |
25 | template <typename T> |
26 | typename std::enable_if_t<std::is_integral<T>::value, T> min(T a, T b) { |
27 | return std::min(a, b); |
28 | } |
29 | |
30 | template <typename T> |
31 | typename std::enable_if_t<std::is_floating_point<T>::value, T> min(T a, T b) { |
32 | return ::fmin(x: a, y: b); |
33 | } |
34 | |
35 | template <typename T, typename... Ts> |
36 | typename std::enable_if_t<std::is_arithmetic<T>::value, T> min(T a, T b, Ts... args) { |
37 | return min(a, min(b, args...)); |
38 | } |
39 | |
40 | } // namespace util |
41 | } // namespace mbgl |
42 | |