3737#include " core/math/randomsequence.h"
3838
3939#include < cassert>
40- #include < stdexcept>
40+
41+ #include < limits>
4142#include < map>
43+ #include < stdexcept>
4244
4345#include < boost/random/mersenne_twister.hpp>
4446#include < boost/random/uniform_int.hpp>
@@ -63,10 +65,6 @@ using boost::uniform_real;
6365using boost::variate_generator;
6466using boost::mt19937;
6567
66- #ifndef SIZE_MAX
67- #define SIZE_MAX ((size_t )-1 )
68- #endif
69-
7068#define PRIME_TABLE_COUNT 25
7169unsigned int primeTable[PRIME_TABLE_COUNT] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 };
7270
@@ -251,7 +249,7 @@ class HybridNumberGenerator : public SeedableNumberGenerator<Type>, public Index
251249/* *
252250 * Template class representing a generator for uniformly distributed numbers in a given range.
253251 */
254- template <class Type , class BoostGenerator , class UniformType , size_t CYCLE_LENGTH = SIZE_MAX >
252+ template <class Type , class BoostGenerator , class UniformType , size_t CYCLE_LENGTH = 0 >
255253class UniformRandomNumberGenerator : public SequentialNumberGenerator <Type>
256254{
257255 public:
@@ -626,7 +624,13 @@ Type UniformRandomNumberGenerator<Type,BoostGenerator,UniformType,CYCLE_LENGTH>:
626624template <class Type , class BoostGenerator , class UniformType , size_t CYCLE_LENGTH>
627625size_t UniformRandomNumberGenerator<Type,BoostGenerator,UniformType,CYCLE_LENGTH>::CycleLength() const
628626{
629- return CYCLE_LENGTH;
627+ if (CYCLE_LENGTH == 0 )
628+ // SIZE_MAX is not mandatory in C++03, and std::numeric_limits<size_t>::max() can't be used
629+ // as a template parameter, so to indicate an "unknown or pretty huge" cycle length we're
630+ // using a template parameter value of 0 instead to convey that information.
631+ return std::numeric_limits<size_t >::max ();
632+ else
633+ return CYCLE_LENGTH;
630634}
631635
632636
@@ -728,9 +732,9 @@ shared_ptr<vector<Type> const> NumberSequenceFactory<Type>::operator()(size_t co
728732 size_t newCount = count;
729733 if (masterSequence->size () > newCount / 2 )
730734 {
731- // make sure to pre-compute at least twice the already-computed size, so we don't waste too much space with
732- if (masterSequence->size () > SIZE_MAX / 2 ) // play it safe (though that'll have us run out of memory anyway)
733- newCount = SIZE_MAX ;
735+ // make sure to pre-compute at least twice the already-computed size
736+ if (masterSequence->size () > std::numeric_limits< size_t >:: max () / 2 ) // play it safe (though that'll have us run out of memory anyway)
737+ newCount = std::numeric_limits< size_t >:: max () ;
734738 else
735739 newCount = masterSequence->size () * 2 ;
736740 }
0 commit comments