Thread overview | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 18, 2014 Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
I've created pull request, which introduces multiple alias this. https://github.com/D-Programming-Language/dmd/pull/3998 Please see the additional tests and comment it. |
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to IgorStepanov | On 18/09/2014 11:20 p.m., IgorStepanov wrote:
> I've created pull request, which introduces multiple alias this.
> https://github.com/D-Programming-Language/dmd/pull/3998
> Please see the additional tests and comment it.
Awesome was waiting for something like this!
Also did we ever consider alias this = ...; syntax?
|
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | On Thursday, 18 September 2014 at 12:51:48 UTC, Rikki Cattermole wrote:
> On 18/09/2014 11:20 p.m., IgorStepanov wrote:
>> I've created pull request, which introduces multiple alias this.
>> https://github.com/D-Programming-Language/dmd/pull/3998
>> Please see the additional tests and comment it.
>
> Awesome was waiting for something like this!
>
> Also did we ever consider alias this = ...; syntax?
It clashes with (not yet supported) aliasing of constructors.
|
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to IgorStepanov | On 18/09/2014 12:20, IgorStepanov wrote: > I've created pull request, which introduces multiple alias this. > https://github.com/D-Programming-Language/dmd/pull/3998 > Please see the additional tests and comment it. http://cdn.meme.li/instances/500x/54451116.jpg In before the rest... -- Bruno Medeiros https://twitter.com/brunodomedeiros |
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to IgorStepanov | On 09/18/2014 04:20 AM, IgorStepanov wrote:
> I've created pull request, which introduces multiple alias this.
> https://github.com/D-Programming-Language/dmd/pull/3998
> Please see the additional tests and comment it.
Awesome!
This is the feature that I thought would never get implemented. :)
Ali
|
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Thursday, 18 September 2014 at 18:38:57 UTC, Ali Çehreli wrote:
> On 09/18/2014 04:20 AM, IgorStepanov wrote:
>> I've created pull request, which introduces multiple alias this.
>> https://github.com/D-Programming-Language/dmd/pull/3998
>> Please see the additional tests and comment it.
>
> Awesome!
>
> This is the feature that I thought would never get implemented. :)
>
> Ali
No, these are rvalue references. ;)
|
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to IgorStepanov | IgorStepanov:
> I've created pull request, which introduces multiple alias this.
Can someone show one or more usage cases?
Thank you,
bye,
bearophile
|
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Thursday, 18 September 2014 at 19:52:42 UTC, bearophile wrote:
> IgorStepanov:
>> I've created pull request, which introduces multiple alias this.
>
> Can someone show one or more usage cases?
>
> Thank you,
> bye,
> bearophile
Do you ask about alias this or about it multiple usage. Multiple usage is similar to single, but multiple:)
struct Foo
{
string s;
int i;
alias s this;
alias i this;
}
Foo f = {"foo", 42};
string s = f; //s == "foo"
int i = f; //i == 42
If there are many different ways to resolve alias this then error is raised:
struct Bar
{
double d;
int i;
alias d this;
alias i this;
}
Foo f = {1.0, 42};
double d = f; //Error: compiler doesn't know, f.d or f.i do you want.
In the next expamle, compiler can resolve conflict:
struct Base1
{
int i;
alias i this;
}
struct Base2
{
int i;
alias i this;
}
struct Derived
{
Base1 b1;
Base2 b2;
int i;
alias b1 this;
alias b2 this;
alias i this;
}
Derived d = Derived(Base1(1), Base2(2), 3);
int i = d; //i == 3;
This done because Derived author know, how to cast his struct to int, and if he say alias i this; this alias hide aliases in base types.
However, if base type contains alias this to another acceptable type, and derived typ hasn't exactly castable alias this then error will be raised:
struct Base1
{
short s;
alias s this;
}
struct Base2
{
int i;
alias i this;
}
struct Derived
{
Base1 b1;
Base2 b2;
int i;
alias b1 this;
alias b2 this;
alias i this;
}
Derived d = Derived(Base1(1), Base2(2), 3);
int i = d; //Ok i == 3;
long l = d; //Error: what do you want? d.i or d.b1.s?
For additional info you can see examples in my pull request.
|
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to IgorStepanov | On Thursday, 18 September 2014 at 11:20:49 UTC, IgorStepanov wrote:
> I've created pull request, which introduces multiple alias this.
> https://github.com/D-Programming-Language/dmd/pull/3998
> Please see the additional tests and comment it.
Exciting!
What more good things than a better behaving Nullable(T) with T being a polymorphic class will this enable?
|
September 18, 2014 Re: Multiple alias this is coming. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Thursday, 18 September 2014 at 21:29:10 UTC, Nordlöw wrote:
> On Thursday, 18 September 2014 at 11:20:49 UTC, IgorStepanov wrote:
>> I've created pull request, which introduces multiple alias this.
>> https://github.com/D-Programming-Language/dmd/pull/3998
>> Please see the additional tests and comment it.
>
> Exciting!
>
> What more good things than a better behaving Nullable(T) with T being a polymorphic class will this enable?
Is Nullable!(T) with polymorphic type disallowed now?
This PR also allows to use inherited alias thises:
interface Intable
{
@property int getInt();
}
class Foo : Intable
{
int i;
this (int i)
{
this.i = i;
}
override @property int getInt()
{
return i;
}
}
auto f = new Foo(42);
int i = f; //i now 42
This option was disabled early.
|
Copyright © 1999-2021 by the D Language Foundation