sources/basics.h

branch
protocol5
changeset 165
718a8c4df538
parent 161
1c483b54ddcb
child 179
7fc34735178e
equal deleted inserted replaced
160:cf514fa0f1cc 165:718a8c4df538
76 T min (T a, T b) 76 T min (T a, T b)
77 { 77 {
78 return (a < b) ? a : b; 78 return (a < b) ? a : b;
79 } 79 }
80 80
81 template<typename ContainerType>
82 typename ContainerType::value_type min(const ContainerType& container)
83 {
84 typename ContainerType::value_type result;
85
86 for (typename ContainerType::value_type element : container)
87 result = min(result, element);
88
89 return result;
90 }
91
81 template<typename T> 92 template<typename T>
82 T max (T a, T b) 93 T max (T a, T b)
83 { 94 {
84 return (a > b) ? a : b; 95 return (a > b) ? a : b;
96 }
97
98 template<typename ContainerType>
99 typename ContainerType::value_type max(const ContainerType& container)
100 {
101 typename ContainerType::value_type result;
102
103 for (typename ContainerType::value_type element : container)
104 result = max(result, element);
105
106 return result;
85 } 107 }
86 108
87 template<typename T> 109 template<typename T>
88 T clamp (T a, T b, T c) 110 T clamp (T a, T b, T c)
89 { 111 {

mercurial