Representation length of integral types
tcak via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 3 21:10:32 PDT 2015
There is a use case for me that I am given a string, and before
even trying to convert it to integer, I want to check whether it
is valid. One of the checks necessary for this is the length of
string.
So, if I have received "156" and it should be converted to ubyte,
I would check whether it is at most 3 bytes length.
While doing that someone would define that maximum length in the
code, while length information is constant and never changes.
For this reason, however data types have properties like max,
min, and init, I would ask for addition of new properties for
integral (even for floating points as well) types as (Example
values for ubyte):
max_hex_length = 2
max_dec_length = 3
max_bin_length = 8
More information about the Digitalmars-d
mailing list