Result total() const { return *scalar; }
};
-template <class T>
+template <class T, class Enabled=void>
class FunctorProxy : public ProxyInfo
{
private:
Result total() const { return (*functor)(); }
};
+/**
+ * Template specialization for type std::function<Result()> which holds a copy
+ * of its target instead of a pointer to it. This makes it possible to use a
+ * lambda or other type inline without having to keep track of an instance
+ * somewhere else.
+ */
+template <class T>
+class FunctorProxy<T,
+ typename std::enable_if<std::is_constructible<std::function<Result()>,
+ const T &>::value>::type> : public ProxyInfo
+{
+ private:
+ std::function<Result()> functor;
+
+ public:
+ FunctorProxy(const T &func) : functor(func) {}
+ Counter value() const { return functor(); }
+ Result result() const { return functor(); }
+ Result total() const { return functor(); }
+};
+
/**
* A proxy similar to the FunctorProxy, but allows calling a method of a bound
* object, instead of a global free-standing function.
return this->self();
}
+ template <class T>
+ Derived &
+ functor(const T &func)
+ {
+ proxy = new FunctorProxy<T>(func);
+ this->setInit();
+ return this->self();
+ }
+
template <class T>
Derived &
functor(T &func)
Vector2d s16;
Value s17;
Value s18;
+ Value s19;
Histogram h01;
Histogram h02;
Histogram h03;
Histogram h12;
SparseHistogram sh1;
- Vector s19;
Vector s20;
+ Vector s21;
Formula f1;
Formula f2;
.desc("this is stat 18")
;
+ s19
+ .functor([]() { return 0; })
+ .name("Stat19")
+ .desc("this is stat 19")
+ ;
+
h01
.init(11)
.name("Histogram01")
.desc("this is formula 4")
;
- s19
- .init(2)
- .name("Stat19")
- .desc("this is statistic 19 for vector op testing")
- .flags(total | nozero | nonan)
- ;
s20
.init(2)
.name("Stat20")
.desc("this is statistic 20 for vector op testing")
.flags(total | nozero | nonan)
;
+ s21
+ .init(2)
+ .name("Stat21")
+ .desc("this is statistic 21 for vector op testing")
+ .flags(total | nozero | nonan)
+ ;
f6
.name("vector_op_test_formula")
f4 += constant(10.0);
f4 += s5[3];
f5 = constant(1);
- f6 = s19/s20;
+ f6 = s20/s21;
}
void
sh1.sample(random() % 10000);
}
- s19[0] = 1;
- s19[1] = 100000;
- s20[0] = 100000;
- s20[1] = 1;
+ s20[0] = 1;
+ s20[1] = 100000;
+ s21[0] = 100000;
+ s21[1] = 1;
}