const debacle

Janice Caron caron800 at googlemail.com
Mon Mar 24 06:35:14 PDT 2008


On 24/03/2008, Jarrod <qwerty at ytre.wq> wrote:
>  Maybe I'm tired, but how does sliceof() fix this? =/

It indicates to the compiler exactly what you want to do. Knowing
this, the compiler is then able to syntax-check the function for
errors, on the assumption that the only valid return values are slices
of the specified variable. Attempting to return anything else becomes
a compile-error. In effect, it allows the compiler to infer the
explicit cast which Daniel919 wrote in explicitly. Remember, if the
compiler cannot prove that it is safe, then the compiler must insist
on the presence of an explicit cast. By telling the compiler exactly
what you want to do, you allow the compiler to deduce that such a cast
would be safe.

But returning a range would fix it better! :-) It's more powerful, and
/way/ less confusing.



More information about the Digitalmars-d mailing list