Bug 1338374 - Make tl::Min/Max variadic. r=froydnj
authorJeff Walden <jwalden@mit.edu>
Mon, 30 Jan 2017 15:56:05 -0800
changeset 342886 eb11f699091d1fa8ce5dc0ef671868feeb179778
parent 342885 f8970aa3b2d621c962cc9fbc29de2b1ae54f6bfb
child 342887 81b228f0a7708c889f2d90627ff2199bc4284565
push id31366
push usercbook@mozilla.com
push dateWed, 15 Feb 2017 11:25:19 +0000
treeherdermozilla-central@c0807d6938c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1338374
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1338374 - Make tl::Min/Max variadic. r=froydnj
mfbt/TemplateLib.h
--- a/mfbt/TemplateLib.h
+++ b/mfbt/TemplateLib.h
@@ -22,25 +22,44 @@
 
 #include "mozilla/TypeTraits.h"
 
 namespace mozilla {
 
 namespace tl {
 
 /** Compute min/max. */
-template<size_t I, size_t J>
+template<size_t Size, size_t... Rest>
 struct Min
 {
-  static const size_t value = I < J ? I : J;
+  static constexpr size_t value =
+    Size < Min<Rest...>::value
+    ? Size
+    : Min<Rest...>::value;
 };
-template<size_t I, size_t J>
+
+template<size_t Size>
+struct Min<Size>
+{
+  static constexpr size_t value = Size;
+};
+
+template<size_t Size, size_t... Rest>
 struct Max
 {
-  static const size_t value = I > J ? I : J;
+  static constexpr size_t value =
+    Size > Max<Rest...>::value
+    ? Size
+    : Max<Rest...>::value;
+};
+
+template<size_t Size>
+struct Max<Size>
+{
+  static constexpr size_t value = Size;
 };
 
 /** Compute floor(log2(i)). */
 template<size_t I>
 struct FloorLog2
 {
   static const size_t value = 1 + FloorLog2<I / 2>::value;
 };