# HG changeset patch # User Teemu Piippo # Date 1469265260 -10800 # Node ID 1c483b54ddcba194a6a857d3e01577074189c6ff # Parent de7574d292ad616ccb013e70819cb1fec3387d55 Added versions of min() and max() that find the smallest and largest values in an iterable. diff -r de7574d292ad -r 1c483b54ddcb sources/basics.h --- a/sources/basics.h Fri Jul 22 17:52:23 2016 +0300 +++ b/sources/basics.h Sat Jul 23 12:14:20 2016 +0300 @@ -78,12 +78,34 @@ return (a < b) ? a : b; } +template +typename ContainerType::value_type min(const ContainerType& container) +{ + typename ContainerType::value_type result; + + for (typename ContainerType::value_type element : container) + result = min(result, element); + + return result; +} + template T max (T a, T b) { return (a > b) ? a : b; } +template +typename ContainerType::value_type max(const ContainerType& container) +{ + typename ContainerType::value_type result; + + for (typename ContainerType::value_type element : container) + result = max(result, element); + + return result; +} + template T clamp (T a, T b, T c) {