On Thu, 18 Dec 2014 22:46:04 +0000 Jonathan Marler via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> What are peoples thoughts on having an inferred type for "cast"? > Good/Bad idea? If good, how helpful would this be? Would this > break existing code somehow? I think this feature would be a nice > added convenience. Not super helpful but nice to have. > > Here's the details > ------------------- > Typed Cast: cast(T)v > try to cast v to T > Type Inferred Cast: cast(auto)v > try to cast v to whatever type is required in the current > context > > void foo(string s) > { > // ... > } > void main() > { > const(char)[] s = "hello"; > foo(cast(string)s); // Current > foo(cast(auto) s); // The type of the cast is inferred to be > a string > foo(cast() s); // Another possible syntax > } > > This would help refactoribility. If a function argument changes > it's type, and the caller is using a cast, then the caller's cast > type will be updated automatically. Note that if it changes to > an invalid type, the cast will still fail like normal. using casts is a bad practice. and "auto casts" is... i can't even find a word. the only thing this will help is to hide bugs, i believe. please, don't. nothing personal, i'm just terrified by the idea.
signature.asc
Description: PGP signature