Continuing on the train of thought started in bounds
class I presented a few days ago in Bounds, and staying within them.
As so often happens, just having bounds
available made me think of what variants of it could be useful. For instance, it would be handy to have it work for floating point or non-POD types, which isn’t possible as it is written. Since the bounds
class uses ‘non-type template parameters‘ for its limits, only integer types and enums are accepted.[1]
Even disregarding this restriction, I found that I had use for a dynamic range
class, as opposed to the static bounds
which has its boundaries set at compile time. Just a simple one, and like std::pair
only having two values, but with both of the same type, and with them guaranteed to be ordered.
The last part there would make it a bit more complex than the simple std::pair
struct, as I’d need to validate the values given in order to ensure that the minimum was lower than or equal to the maximum, but still, a simple enough little class.