src/maths.h

changeset 122
b54b350dff5d
parent 120
8c9fff699241
--- a/src/maths.h	Fri Jul 30 01:28:39 2021 +0300
+++ b/src/maths.h	Fri Aug 27 00:55:32 2021 +0300
@@ -72,7 +72,32 @@
 	}
 	constexpr double infinity = std::numeric_limits<double>::infinity();
 	constexpr long double pi = M_PIl;
-
+	// Returns the minimum value of a container
+	template<typename T>
+	inline auto nmin(T&& values)
+	{
+		auto it = std::begin(values);
+		auto result_p = it;
+		for (++it; it != std::end(values); ++it)
+		{
+			if (*it < *result_p)
+				result_p = it;
+		}
+		return *result_p;
+	}
+	// Returns the maximum value of a container
+	template<typename T>
+	inline auto nmax(T&& values)
+	{
+		auto it = std::begin(values);
+		auto result_p = it;
+		for (++it; it != std::end(values); ++it)
+		{
+			if (*it > *result_p)
+				result_p = it;
+		}
+		return *result_p;
+	}
 	/*
 	 * Returns the empty sum. (recursion base)
 	 */

mercurial