No, there are no base classes shared by all distribution patterns. Even if that were the case, your intended approach would not work due to fragmentation of objects .
However, it’s quite simple to create your own base class and extract from it.
class base_distribution {}; template<typename ...Args> class normal_distribution : public base_distribution, public std::normal_distribution<Args...> {}; template<typename ...Args> class uniform_int_distribution : public base_distribution, public std::inform_int_distribution<Args...> {};
... etc. for any distributions you want to support. You will probably also need to delegate shell constructors to their actual distribution base class for maximum transparency.
At this point, slicing objects becomes a factor, so you cannot just drag base_distribution into a class as a member, or insert it into a vector, and expect it to work. You will have to use at least
std::shared_ptr<base_distribution>
as a member of a class or container value. At this point, to wrap this around, define any virtual methods that you need in your base_distribution class and implement them accordingly in the template subclasses.
source share