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:

enter image description here

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

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -