
AMDG Neal Becker wrote:
Joseph Wakeling wrote:
Suppose that I have a function that takes a uniform random number generator as an argument, e.g.
double foo(mt19937 &urng) { double x = uniform_real<double> (0.0, 10.0) (urng); double y = uniform_real<double> (5.0, 7.0) (urng);
return (x*y); }
Is there a way to make the choice of random number generator arbitrary (i.e. not limited to mt19937) without making the function a template? Alternatively, is there a better way of passing around the basic uniform random number generator?
The reason for the no-template rule is that I would like to pass a URNG to a virtual function in a class, and I would really not like to have to make the class itself a template dependent on the type of URNG.
Can someone recommend a solution?
Thanks and best wishes,
member func can be template without class class being template.
A virtual function can't be a template.
You might be able to use something like this:
template<class ResultType>
class runtime_generator {
public:
ResultType min() const { return min_; }
ResultType max() const { return max_; }
ResultType operator()() { return impl(); }
private:
ResultType min_, max_;
boost::function