Why boost uniform_int_distribution takes a closed range (instead of a half-open range, following common C++ usage)? -
the title says all. there's warning in documentation pages:
why this, when common practice in c++ use open ranges [begin, end) ?
only closed ranges, can create uniform_int_distribution
, produces integer:
uniform_int_distribution<int> dist(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
if half-open range, never reach std::numeric_limits<int>::max()
, std::numeric_limits<int>::max() - 1
.
it's same situation std::uniform_int_distribution
in c++11 standard library.
half-open ranges iterators common, because 1 can express empty ranges (by setting begin == end
). doesn't make sense distributions.
reference: stephan t. lavavej mentions exact reason in talk "rand() considered harmful" @ going native 2013 (around minute 14). talk c++11 <random>
, of course same reasoning applies boost well.
Comments
Post a Comment