Why is there a param_type sub class in random distributions?

T

thijs

Can someone motivate the design choice that led to random distributions having their parameters stored in the param_type sub class?

E.g. the uniform integer distribution has two parameter a and b that specify the bounds.

uniform_int_distribution<> dice(1,6);

dice.a(); // gives a
dice.b(); // gives b

However, all distributions also have a param() member funtion and a nested class param_type that captures all the distribution parameters.

dice.param().a() // give also a
dice.param().b() // give also b


Why has it been decided to move the parameters of the distribution to a nested class param_type?? Why not simply store them in the distribution class directly?
 
S

Stefan Ram

Why has it been decided to move the parameters of the
distribution to a nested class param_type?? Why not simply
store them in the distribution class directly?

A param_type object can also be passed for temporary use in
a call of the distribution. It is not only used as a nested
type. So it has a certain autonomy. When the parameters are
bundled as an object, it might be more easy to safe or
restore them together as a unit with a single expression.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top