On 2012-48-15 06:12, Jonathan M Davis <[email protected]> wrote:

I don't see any reason not to support it. if you want coversion to only go one way, then alias a function which returns the value being aliased rather than aliasing a variable. If it doesn't support implicit conversions from other types, then it's impossible to have such implicit conversion in D, and I don't
see any reason why it should be disallowed like that, not when you've
explicitly said that you want to do an alias like that.

There is a need for clarification for implicit construction of types with
multiple fields and alias this, though. What does this do:

struct S {
   int n;
   string s;
   alias s this;
}

S s = "Foo!";


I can see a few solutions:

1) Disallow implicit construction of these types from the aliased type.
    The problem with this solution is default initialization of other
    fields may be exactly what you want. There may also be problems
    where functions are used for alias this.
2) Default construct the wrapper type, then apply alias this.
3) Use some specialized constructor. Will require some annotation or
    other way to mark it as implicit (@implicit?).


Another, likely less common, problem is with classes with alias this:

class A {
   int n;
   alias n this;
}

A a = 4;


Should this allocate a new A?

--
Simen

Reply via email to