D
Dave
Hello all,
Suppose you have an unsigned integral type T. It's not one of the built-in
types, but rather typedefed off of one of the built-in unsigned integral
types (but we don't know which one).
I want to find the maximum value for this type. This seems to work just
fine:
static_cast<T>(-1)
Is there any reason this should be avoided? Or is this indeed guaranteed to
do the job on a standard-conforming compiler?
I'm not using numeric_limits<> to get the maximum value because, as stated
above, I don't know the underlying built-in type, so I don't know which
specialization of numeric_limits<> to use.
In case anyone is wondering, the type I'm actually working with is
string::size_type. I need to get the maximum value for this type, but,
according to Josuttis, I can only be assured the underlying type is unsigned
integral, but there are no guarantees as to which of the unsigned integral
types it is...
Does this look clean to everyone?
Thanks,
Dave
Suppose you have an unsigned integral type T. It's not one of the built-in
types, but rather typedefed off of one of the built-in unsigned integral
types (but we don't know which one).
I want to find the maximum value for this type. This seems to work just
fine:
static_cast<T>(-1)
Is there any reason this should be avoided? Or is this indeed guaranteed to
do the job on a standard-conforming compiler?
I'm not using numeric_limits<> to get the maximum value because, as stated
above, I don't know the underlying built-in type, so I don't know which
specialization of numeric_limits<> to use.
In case anyone is wondering, the type I'm actually working with is
string::size_type. I need to get the maximum value for this type, but,
according to Josuttis, I can only be assured the underlying type is unsigned
integral, but there are no guarantees as to which of the unsigned integral
types it is...
Does this look clean to everyone?
Thanks,
Dave