Should alias this support implicit construction in function calls and return statements?

Simen Kjaeraas simen.kjaras at gmail.com
Thu Dec 13 08:37:33 PST 2012


On 2012-28-13 17:12, d coder <dlang.coder at gmail.com> wrote:

> I do not know if I am missing something but consider:
>
> struct Foo {
>   int r;
>   int i;
>   bool get() {
>     return true;  // always return true
>   }
>   alias get this;
> }
>
> So I am wondering how it would be possible to construct Foo from a bool?
> Otherwise how would the compiler be able to figure out in what scenarios
> reverse conversion is possible and is intended.

get is not an lvalue. If you attempt this today:

struct S {
     bool get() @property {
         return true;
     }
     alias get this;
}

S s;
s = false;

you should get a nice compile error. This would of course also apply in
this new situation. Now, this:

struct S {
     bool get() @property {
         return true;
     }
     void get(bool value) @property {
     }
     alias get this;
}

S s;
s = false;

should work. Given this, I believe default-constructing the value, then
applying normal alias this rules, makes the most sense.

-- 
Simen


More information about the Digitalmars-d mailing list