Amit Bhatia wrote:
Thanks Jim,
I have another doubt which is due to my lack of any previous
experience
with things like templates(Well I am seeing the kind of
programming used in
BOOST for the first time :( ). I was looking at the random
number library,
and it mentions IntType a number of times. I can't figure out
where to look
for it? So is it a generic thing or is it part of some other
BOOST library.
It's right under your nose, as they say ;=)
The IntType is a parameter to the template, so it's whatever you tell the
compiler you want it to be.
Taking a snip at (ahem) random from one of the files:
template
class linear_congruential
{
public:
typedef IntType result_type;
static const IntType multiplier = a;
static const IntType increment = c;
static const IntType modulus = m;
static const bool has_fixed_range = true;
static const result_type min_value;
static const result_type max_value;
explicit linear_congruential_fixed(IntType x0 = 1);
// compiler-generated copy constructor and assignment operator are fine
void seed(IntType x0);
IntType operator()();
};
At this point, we don't know exactly what an "IntType" is. However, on the
next lines:
typedef random::linear_congruential minstd_rand0;
typedef random::linear_congruential minstd_rand;
These typedefs provide typedefs that fix IntType as a long, with the various
parameters converted to long.
More detailed explanation about templates is beyond the scope of this list -
it's really quite a basic topic. I'd suggest picking up a good C++ tutorial
book. Koenig and Moo's "Accelerated C++" comes highly recommended (I haven't
read it myself, but I have yet to hear a negative review of it).
--
Jim