Should alias this support implicit construction in function calls and return statements?
Simen Kjaeraas
simen.kjaras at gmail.com
Thu Dec 13 08:15:02 PST 2012
On 2012-38-13 15:12, Adam D. Ruppe <destructionator at gmail.com> wrote:
> On Thursday, 13 December 2012 at 14:25:27 UTC, Simen Kjaeraas wrote:
>> foo(b); // Cannot implicitly convert byte to bbyte.
>
> I think the way it is now is correct for alias this.. it is kinda like
> implicitly casting to a base class. That's correct, but going to a
> superclass isn't necessarily right. You might only want it to be one
> way. Suppose you had something like this:
>
> struct SafeText {
> string text;
> alias this text;
> }
>
> Safe text should implicitly convert to plain string text, but it
> shouldn't go the other way automatically.
But this is easily solved:
struct SafeText {
string text;
string get( ) @property {
return text;
}
alias get this;
}
This is just as explicit as what you propose, and possible with what we
currently have.
>> A long time ago, when dinosaurs roamed the earth, walterandrei.pdf[5]
>> suggested that opImplicitCastTo and opImplicitCastFrom take care of
>> this conversion.
>
> A separate function or facility for implicit cast to might be ok though.
--
Simen
More information about the Digitalmars-d
mailing list