Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Number
Performance ImprovementsAfter observing that
Number
initialized a mersenne twister and random generator on the stack on each call of the functioninteger
, I moved them out of the function and stored them as a statically-initialized member of theNumber
class, this improves performance by skipping the initialization of these objects whenever a number is generated, meaning that the performance ofinteger
is now closer to what one would get by directly using the standard library, a worthwhile improvement considering thatNumber
is also used as a helper in other modules.Number
Type SafetyChanged the
Number
module to be header-only, this allows us to make the class a template that can work with any integral type. Through concepts we can constrain the templated typeT
to be of typestd::integral
, while allowing the user to generate a wider range of numbers from the same interface, such asunsigned int
s,size_t
s, etc... One immediate benefit of this is that in theHelper
module we are now able to index the whole theoretical range of astd::vector
, by generating asize_t
instead of anint
.Quality-of-Life changes
Swapped the order of
integer
's arguments, it makes much more sense to havemin
come beforemax
. The "max by default" behavior is provided by an overload that accepts a single parameter and correctly calls the two-arguments function, checkNumber.h
to see what I mean. All tests have been changed accordingly (the order of parameters has been swapped to the sensible one) and a test has been added to check that the overload is correctly resolved.