September 19, 2014
On Friday, 19 September 2014 at 11:25:03 UTC, Nordlöw wrote:
> On Thursday, 18 September 2014 at 22:13:14 UTC, IgorStepanov wrote:
>> Is Nullable!(T) with polymorphic type disallowed now?
>
> Sorry, I meant
>
>     NotNull(T)
>
> Here's a module
>
> https://github.com/nordlow/justd/blob/master/notnull.d
>
> a bit tweak from the original design by Adam D Ruppe.

What does a troubles with your NotNull implementation you have with old alias this?
Do you want to implicit cast from NotNull!(T) to all other NotNull!(B) where B is basetype of T?
September 19, 2014
On Friday, 19 September 2014 at 13:24:53 UTC, IgorStepanov wrote:
> On Friday, 19 September 2014 at 11:25:03 UTC, Nordlöw wrote:
>> On Thursday, 18 September 2014 at 22:13:14 UTC, IgorStepanov wrote:
>>> Is Nullable!(T) with polymorphic type disallowed now?
>>
>> Sorry, I meant
>>
>>    NotNull(T)
>>
>> Here's a module
>>
>> https://github.com/nordlow/justd/blob/master/notnull.d
>>
>> a bit tweak from the original design by Adam D Ruppe.
>
> What does a troubles with your NotNull implementation you have with old alias this?
> Do you want to implicit cast from NotNull!(T) to all other NotNull!(B) where B is basetype of T?

That makes me think of a question:

Will the compiler instantiate a template member function, if it is specified as alias this?

    struct MyStruct {
        T convertTo(T)()
            if(...)
        {
            // implementation
        }

        alias convertTo this;
    }

    MyStruct s;
    int a = s;
    float b = s;
    string c = s;

Will this work?
September 19, 2014
On Friday, 19 September 2014 at 14:23:55 UTC, Marc Schütz wrote:
> On Friday, 19 September 2014 at 13:24:53 UTC, IgorStepanov wrote:
>> On Friday, 19 September 2014 at 11:25:03 UTC, Nordlöw wrote:
>>> On Thursday, 18 September 2014 at 22:13:14 UTC, IgorStepanov wrote:
>>>> Is Nullable!(T) with polymorphic type disallowed now?
>>>
>>> Sorry, I meant
>>>
>>>   NotNull(T)
>>>
>>> Here's a module
>>>
>>> https://github.com/nordlow/justd/blob/master/notnull.d
>>>
>>> a bit tweak from the original design by Adam D Ruppe.
>>
>> What does a troubles with your NotNull implementation you have with old alias this?
>> Do you want to implicit cast from NotNull!(T) to all other NotNull!(B) where B is basetype of T?
>
> That makes me think of a question:
>
> Will the compiler instantiate a template member function, if it is specified as alias this?
>
>     struct MyStruct {
>         T convertTo(T)()
>             if(...)
>         {
>             // implementation
>         }
>
>         alias convertTo this;
>     }
>
>     MyStruct s;
>     int a = s;
>     float b = s;
>     string c = s;
>
> Will this work?

No, this isn't work.
You can start discussion about this feature and if it be approved, it can be implemented in future.
September 19, 2014
On 9/19/14, 3:21 AM, Dicebot wrote:
> On Friday, 19 September 2014 at 09:34:22 UTC, ponce wrote:
>> Call me unimaginative, but I'm struggling to see any use case for
>> multiple alias this, and I struggle even more for such constructors
>> aliasing.
>
> Pretty much every single time you have ever wanted to do multiple
> inheritance of implementation multiple `alias this` was the proper tool
> for a job. I notice myself thinking "this could have been done much
> cleaner with multiple alias this" at least once a month :)

Yah, multiple subtyping of structs is terrific to have. Thanks Igor for this work! -- Andrei

September 19, 2014
On Friday, 19 September 2014 at 13:24:53 UTC, IgorStepanov wrote:
> What does a troubles with your NotNull implementation you have with old alias this?
> Do you want to implicit cast from NotNull!(T) to all other NotNull!(B) where B is basetype of T?

Yes, that is what I want, but last time I checked DMD didn't allow me to.
September 19, 2014
On Friday, 19 September 2014 at 17:59:44 UTC, Nordlöw wrote:
> On Friday, 19 September 2014 at 13:24:53 UTC, IgorStepanov wrote:
>> What does a troubles with your NotNull implementation you have with old alias this?
>> Do you want to implicit cast from NotNull!(T) to all other NotNull!(B) where B is basetype of T?
>
> Yes, that is what I want, but last time I checked DMD didn't allow me to.

This PR doesn't allow template alias this, however you can iterate all subtypes for you class T (D meta-programming features allow you to do it now) and mixin different alias this declaration for all of this types.
September 19, 2014
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.

Further, could this also be used to somehow simplify hierarchically defined enumerators? Typically the enumerators and predicates related to the enumeration WordKind defined here

https://github.com/nordlow/justd/blob/master/languages.d#L485
September 19, 2014
On Friday, 19 September 2014 at 17:19:09 UTC, Andrei Alexandrescu
wrote:
> On 9/19/14, 3:21 AM, Dicebot wrote:
>> On Friday, 19 September 2014 at 09:34:22 UTC, ponce wrote:
>>> Call me unimaginative, but I'm struggling to see any use case for
>>> multiple alias this, and I struggle even more for such constructors
>>> aliasing.
>>
>> Pretty much every single time you have ever wanted to do multiple
>> inheritance of implementation multiple `alias this` was the proper tool
>> for a job. I notice myself thinking "this could have been done much
>> cleaner with multiple alias this" at least once a month :)
>
> Yah, multiple subtyping of structs is terrific to have. Thanks Igor for this work! -- Andrei

You are welcome :)
BTW. Please comment (approve or correct) semantic rules, which
used for conflict resolving.
I've written it early and reflected it in the PR tests.
September 19, 2014
On Thursday, 18 September 2014 at 20:11:12 UTC, IgorStepanov wrote:
> Do you ask about alias this or about it multiple usage. Multiple usage is similar to single, but multiple:)

Just an FYI, bearophile is very knowledgeable about D and one of the oldest community members, he holds the record for most bugs opened.

This doesn't mean he knows everything, but it certainly makes it clear he was asking, "why would you want to use multiple alias this." As others mention kind of like "why would you want to use multiple inheritance."
September 19, 2014
19-Sep-2014 02:16, bearophile пишет:
> IgorStepanov:
>
>> Do you ask about alias this or about it multiple usage. Multiple usage
>> is similar to single, but multiple:)
>
> I meant the multiple usage. And none of your examples here are use cases
> :-( I'd like to see one use case, or more.
>

For instance one could implement OOP and polymorphism on structs, all in library code.

struct Base {  .... }

struct Itnerface { .... }

struct Derived{
	Base _super;
	Interface _iface;
	alias this _super;
	alias this _iface;
}

I recall trying something like that but stopping because I needed multiple alias this.


-- 
Dmitry Olshansky
1 2 3 4