I have this class that makes a path for a montecarlo simulator where it takes creates paths of integers from an array of available ints. So for example we could have a path of length 3 drawn from the array containing {0,1,2,3,4} and this would for example generate 3,1,2 and 1,4,0.
//This path generator just generates a list of ints for each path
template< typename randgen >
class MCPathGen {
public:
typedef vector< int > mcpath_t;
typedef randgen randgen_t;
typedef typename add_lvalue_reference<randgen>::type randgen_ref_t;
MCPathGend(randgen_ref_t r) : m_rgen(r) {}
//generate a single path by shuffling a copy of blank_d
mcpath_t operator()() {
Chooser< randgen_t > choose(m_rgen);
mcpath_t path_temp(blank_d.begin(), blank_d.end());
random_shuffle(path_temp.begin(), path_temp.end(), choose);
return path_temp;
};
private:
randgen_ref_t m_rgen;
};
Now I'm not quite sure what my colleague has done by using typedef typename add_lvalue_reference<randgen>::type randgen_ref_t;
What does add_lvalue_reference do? Is this necessary for making the code work?
I have not seen this before, so any insight is appreciated!
See Question&Answers more detail:os