|
@@ -20,26 +20,29 @@
|
20
|
20
|
*
|
21
|
21
|
*/
|
22
|
22
|
|
23
|
|
-#pragma once
|
24
|
|
-
|
25
|
23
|
#undef MIN
|
26
|
24
|
#undef MAX
|
27
|
25
|
|
28
|
26
|
#ifdef __cplusplus
|
29
|
27
|
|
30
|
|
- extern "C++" {
|
|
28
|
+ #ifndef _MINMAX_H_
|
|
29
|
+ #define _MINMAX_H_
|
|
30
|
+
|
|
31
|
+ extern "C++" {
|
|
32
|
+
|
|
33
|
+ // C++11 solution that is standards compliant. Return type is deduced automatically
|
|
34
|
+ template <class L, class R> static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
|
|
35
|
+ return lhs < rhs ? lhs : rhs;
|
|
36
|
+ }
|
|
37
|
+ template <class L, class R> static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
|
|
38
|
+ return lhs > rhs ? lhs : rhs;
|
|
39
|
+ }
|
|
40
|
+ template<class T, class ... Ts> static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
|
|
41
|
+ template<class T, class ... Ts> static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
|
31
|
42
|
|
32
|
|
- // C++11 solution that is standards compliant. Return type is deduced automatically
|
33
|
|
- template <class L, class R> static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
|
34
|
|
- return lhs < rhs ? lhs : rhs;
|
35
|
|
- }
|
36
|
|
- template <class L, class R> static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
|
37
|
|
- return lhs > rhs ? lhs : rhs;
|
38
|
43
|
}
|
39
|
|
- template<class T, class ... Ts> static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
|
40
|
|
- template<class T, class ... Ts> static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
|
41
|
44
|
|
42
|
|
- }
|
|
45
|
+ #endif
|
43
|
46
|
|
44
|
47
|
#else
|
45
|
48
|
|