I’m skeptical that C++ can manage anything as clear and concise as:
type Age is new Natural range 0..150; type Age is new Natural range 0..150; using age = in_range<int, 0, 150>;
Not the end of the world(note C++ is a big language that changes a lot)
template<typename T, int min, int max> // probably not int for min/max, but whatever
class in_range {
...
};
which would be instantiated with `using <my_type_name> = ...;` and would have all the necessary operator overloads and checks. Still, it's only bringing in the runtime, not compile time, checks and can't be "turned off" (well, maybe
take a fourth boolean value and have two code paths everywhere that can be optimized down to one if you want to turn off the checks) like it can in Ada (whether that's a good idea or not depends on how well you've proved out your code). It's also introducing all the overhead of an object which isn't necessary in Ada.it's doable to have both compile-time and run-time checks:
https://gcc.godbolt.org/z/oT3adre86
some compile-time interval calculus library would enable more check and does not seem much harder to implement than a run-time one.