On 12.03.14, Öö Tiib:
[snip]
If there is need for int with exact bounds then a template
(most ideas described there
http://accu.org/index.php/journals/313)
is fine enough. Not a rocket science so it is unsure why neither
boost nor standard contains such thing already.
+1.
That would be the first step to catch up with Ada95. Unfortunately,
other features of Ada95 cannot so easily be simulated by a C++ template,
like choosing the right integer type depending on the specified range.
Or am I wrong there?
For example, the declaration of up_to_100K_t leaves the underlying type
open, whereas up_to_100K_t_int explicitely states that Integer should be
used for this type.
type up_to_100K_t is range 0 .. 100000;
type up_to_100K_t is Integer range 0 .. 100000;
Most often it is not necessary to care about the size of the underlying
integer type (whether a loop index is 16 bit, 32 bit or 64 bit is mostly
irrelevant, the compiler should select the most appropriate type).
However, if the size of a type actually matters, you still specify your
restrictions:
for up_to_100K_t use 16; // now the compiler must use a 16 bit type.
IMHO, C++ has still a long way to go ...
Regards,
Stuart
PS: Don't get me wrong, C++ is still my favorite language. In my option
it is far better than Objective C, which I am forced to use for Mac
development.