0

I was generating a random number with the boost library, namely:

   boost::random::random_device rng;
   boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);

Now I understand that uniform_int_distribution is class, but what's the meaning of the empty <>? Is it a template?

  • 1
    I think here its a good explanation about that: https://stackoverflow.com/questions/41312280/what-does-the-symbol-means – Brygom Mar 02 '22 at 20:29
  • 1
    @0x5453 Doesnt <> actually mean something different here? in the case in that answer it means "deduce the template argument from the types of the function call arguments". in this case I think it means "use the default template argument type" which is int here. – jwezorek Mar 02 '22 at 20:34

1 Answers1

2

It is indeed a template. With no given datatype it will fall back to a default datatype to work with.

You can see that the default in this case is a regular int.

https://www.boost.org/doc/libs/1_51_0/doc/html/boost/random/uniform_int_distribution.html

EinMario
  • 36
  • 2
  • In C++17 there is [CTAD](https://en.cppreference.com/w/cpp/language/class_template_argument_deduction), which is more flexible than using `<>` to get the declared defaults: https://wandbox.org/permlink/855oGLe7JLyXbxBO – sehe Mar 03 '22 at 22:52