Try using nested template args for EP templates. Just a sanity check
authorRamprasad Venkataraman <ramv@illinois.edu>
Fri, 30 Mar 2012 19:18:37 +0000 (14:18 -0500)
committerPhil Miller <mille121@illinois.edu>
Thu, 5 Apr 2012 21:17:53 +0000 (16:17 -0500)
tests/charm++/method_templates/pgm.C

index 942619b25cab0ff24bfb6a558623c50105192cc5..803c565053e33517311e2da179711bf3e1ca5d84 100644 (file)
@@ -4,17 +4,21 @@
 #include "mylib.def.h"
 #undef CK_TEMPLATES_ONLY
 #include <iostream>
+#include <functional>
 
 // Utility functors
-class add {
+template <typename cmp>
+class count {
     private:
-        int sum;
+        int threshold, num;
+        cmp c;
     public:
-        add(): sum(0) {}
-        inline void operator() (int i) { sum += i; }
-        void pup(PUP::er &p) { p | sum; }
-        friend std::ostream& operator<< (std::ostream& out, const add& obj) {
-            out << "sum = " << obj.sum;
+        count(const int _t=0): threshold(_t), num(0) {}
+        inline void operator() (int i) { if (c(i, threshold)) num++; }
+        void pup(PUP::er &p) { p | threshold; p | num; }
+        friend std::ostream& operator<< (std::ostream& out, const count& obj) {
+            out << "threshold = "<< obj.threshold << "; "
+                << "num = " << obj.num;
             return out;
         }
 };
@@ -29,7 +33,8 @@ class avg {
         void pup(PUP::er &p) { p | sum; p | num; }
         friend std::ostream& operator<< (std::ostream& out, const avg& obj) {
             out << "num = " << obj.num << "; "
-                << "avg = " << ( obj.num ? obj.sum/obj.num : obj.sum );
+                << "sum = " << obj.sum << "; "
+                << "avg = " << ( obj.num ? (double)obj.sum/obj.num : obj.sum );
             return out;
         }
 };
@@ -38,9 +43,9 @@ class avg {
 // Temporary initproc to register the instantiated EPs
 void register_instantiations()
 {
-    add adder;
+    count< std::less<int> >  comparator;
     avg avger;
-    CkIndex_libArray::doSomething<add>(adder);
+    CkIndex_libArray::doSomething< count<std::less<int> > >(comparator);
     CkIndex_libArray::doSomething<avg>(avger);
 };
 
@@ -58,7 +63,8 @@ class pgm : public CBase_pgm
         }
         
         void startTest() {
-            arrProxy.doSomething(add());
+            //count< std::less<int> > cnt(5);
+            arrProxy.doSomething( count< std::less<int> >(5) );
             arrProxy.doSomething(avg());
         }