casting int[] to bool[]

Brad Roberts braddr at puremagic.com
Wed Jan 28 19:30:38 PST 2009


Bill Baxter wrote:
> On Thu, Jan 29, 2009 at 12:04 PM, Jarrett Billingsley
> <jarrett.billingsley at gmail.com> wrote:
>> On Wed, Jan 28, 2009 at 9:57 PM, Bill Baxter <wbaxter at gmail.com> wrote:
>>> It's just that casting is a very blunt tool and should be avoided
>>> whenever possible, because the compiler won't tell you if you're doing
>>> something completely crazy.
>>>
>>> Here you could use somethign like:
>>>
>>>    dataIn[i][index] = (t!=0);
>>>
>>> instead of casting.
>> Blunt?  Pfah!  cast(bool)int is well-defined.  ;)
> 
> Just you're more likely to catch an error if t changes from being an
> int to something else later on.
> I wish D had a "tame and well-behaved casts only please" kind of cast. :-(
> 
> --bb

Oh, hey, that reminds me..

Walter!  When are we going to get the equivalent to const_cast?  And the
related restriction that cast can't alter constness?

I've already made the mistake at least once changing type and constness,
without meaning to do the latter, at the same time.

Thanks,
Brad



More information about the Digitalmars-d-learn mailing list