Request for forced implicit cast

Frank Benoit keinfarbton at googlemail.com
Fri Aug 22 06:53:58 PDT 2008


When it comes to overloaded functions where not all arguments match
exactly, they must be casted to the arguments types of the method that
should be used.

But when cast(Type) is applied to the arguments and code changes later
on, it can happen the cast hides a compiler error. Because the argument
would no more be implicit castable to the methods arg type.

This is why i would like to have 'soft' cast, that does only help the
compiler to choose which method I want, but only is allowed for implicit
casts.

soft_cast(Type)
implicit_cast(Type)

Or should this be done with templates?
template soft_cast(T){
  T soft_cast(U)( U u ){
    return u; // implicit cast to return type
  }
}

The problem here is, that no error is given for the place of
instantiation, i think. And the syntax is less nice.
  soft_cast!(Type)(ref)




More information about the Digitalmars-d mailing list