89 result = min(result, element); |
89 result = min(result, element); |
90 |
90 |
91 return result; |
91 return result; |
92 } |
92 } |
93 |
93 |
94 template<typename T> |
94 template<typename T, typename TT> |
95 T max (T a, T b) |
95 constexpr std::common_type_t<T, TT> max(T a, TT b) |
96 { |
96 { |
97 return (a > b) ? a : b; |
97 return (a > b) ? a : b; |
98 } |
98 } |
99 |
99 |
100 template<typename ContainerType> |
100 template<typename ContainerType> |
107 |
107 |
108 return result; |
108 return result; |
109 } |
109 } |
110 |
110 |
111 template<typename T, typename TT, typename TTT> |
111 template<typename T, typename TT, typename TTT> |
112 std::common_type_t<T, TT, TTT> clamp(T a, TT b, TTT c) |
112 constexpr std::common_type_t<T, TT, TTT> clamp(T a, TT b, TTT c) |
113 { |
113 { |
114 return (a < b) ? b : (a > c) ? c : a; |
114 return (a < b) ? b : (a > c) ? c : a; |
115 } |
115 } |
116 |
116 |
117 inline const char *plural(int value) |
117 inline const char *plural(int value) |
118 { |
118 { |
119 return value != 1 ? "s" : ""; |
119 return value != 1 ? "s" : ""; |
120 } |
120 } |
121 |
121 |
122 template <typename T, size_t N> |
122 template<typename T, std::size_t N> |
123 char (&_ArraySizeHelper(T (&array)[N]))[N]; |
123 constexpr std::size_t countof(T(&)[N]) |
124 #define countof(array) (sizeof(_ArraySizeHelper( array ))) |
124 { |
|
125 return N; |
|
126 } |
125 |
127 |
126 struct Exitception {}; |
128 struct Exitception {}; |
127 |
129 |
128 #ifdef __GNUC__ |
130 #ifdef __GNUC__ |
129 # define GNUATTRIBUTE(X) __attribute__(X) |
131 # define GNUATTRIBUTE(X) __attribute__(X) |