src/generics/functions.h

changeset 1390
3eace926af7f
parent 1353
48374309f3d1
child 1411
b48f3fd2664b
--- a/src/generics/functions.h	Sat May 26 17:28:15 2018 +0300
+++ b/src/generics/functions.h	Wed May 30 22:31:06 2018 +0300
@@ -224,6 +224,24 @@
 	return static_cast<T>(round(value / interval) * interval);
 }
 
+/*
+ * Returns the empty sum. (recursion base)
+ */
+template<typename T>
+T sum()
+{
+	return {};
+}
+
+/*
+ * Returns the sum of n arguments.
+ */
+template<typename T, typename... Rest>
+T sum(const T& arg, Rest&&... rest)
+{
+	return arg + sum<T>(rest...);
+}
+
 // Copy of qOverload so as to drop Qt version requirement from 5.7 to 5.5.
 #if (QT_VERSION < QT_VERSION_CHECK(5, 7, 0))
 template <typename... Args>

mercurial