c++ - pack (type erase) a random number generator -
the c++11 std library has several random number generators (rng), each implementing concept uniformrandomnumbergenerator . these can used argument random distributions, see this documentation overview. the advantage of design choice of underlying rng engine de-coupled application. however, design requires definition (not merely declarations) of calls rng available (if rng type remain unspecified template parameter). thus, in struct complicated_random_distribution { /* data , auxiliary methods here */ // complicated; may call rng::operator() many times template<typename rng> some_type operator()(rng&gen) const; }; the member operator() cannot straightforwardly implemented in separate compilation unit (cu), must available in same header file (or 1 #include d it). for separate implementation, 1 ideally want way pack rng in same way std::function<> packs callable object. (simply using std::function , providing values rng::min() , rng::max() ...