Boost logo

Boost Users :

From: Jim.Hyslop (jim.hyslop_at_[hidden])
Date: 2003-06-18 16:29:52


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 IntType, IntType a, IntType c, IntType m>
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<long, 16807L, 0, 2147483647L,
     1043618065L> minstd_rand0;
typedef random::linear_congruential<long, 48271L, 0, 2147483647L,
     399268537L> 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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net