]> granicus.if.org Git - clang/commitdiff
Another variadic template metafunction test case: summing values.
authorDouglas Gregor <dgregor@apple.com>
Mon, 3 Jan 2011 17:25:02 +0000 (17:25 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 3 Jan 2011 17:25:02 +0000 (17:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122752 91177308-0d34-0410-b5e6-96231b3b80d8

test/CXX/temp/temp.decls/temp.variadic/metafunctions.cpp

index d9a3b5c27fbf98fd048166ded2aa6c96406b546e..c0a9eb6cd6e31720c543d752e3d74ea2a9be160d 100644 (file)
@@ -65,7 +65,7 @@ namespace Replace {
              tuple<int, int>>::value? 1 : -1];
 }
 
-namespace Multiply {
+namespace Math {
   template<int ...Values>
   struct double_values {
     typedef int_tuple<Values*2 ...> type;
@@ -89,8 +89,22 @@ namespace Multiply {
     typedef int_tuple<(Values*Values)...> type;
   };
 
-  int check2[is_same<square_tuple<int_tuple<1, 2, -3>>::type, 
+  int check2[is_same<square_tuple<int_tuple<1, 2, -3> >::type, 
                      int_tuple<1, 4, 9>>::value? 1 : -1];
+
+  template<int ...Values> struct sum;
+
+  template<int First, int ...Rest> 
+  struct sum<First, Rest...> {
+    static const int value = First + sum<Rest...>::value;
+  };
+
+  template<>
+  struct sum<> {
+    static const int value = 0;
+  };
+
+  int check3[sum<1, 2, 3, 4, 5>::value == 15? 1 : -1];
 }
 
 namespace Indices {