September 19, 2014
On Friday, 19 September 2014 at 18:46:14 UTC, IgorStepanov wrote:
> 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.

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

enum can have a class as base type:

import std.stdio;

class Word
{
     this(string type)
     {
         this.type = type;
     }

     @property abstract string wordClass();

     override size_t toHash() @trusted
     {
         string s = toString();
         return typeid(string).getHash(&s);
     }

     override string toString() @trusted nothrow
     {
         try
         {
             return wordClass() ~ ":" ~ type;
         }
         catch(Throwable th)
         {
             assert(0);
         }
     }

     string type;
}

class Noun : Word
{
     this (string type)
     {
         super(type);
     }

     @property override string wordClass()
     {
         return "noun";
     }
}

class Verb : Word
{
     this (string type)
     {
         super(type);
     }

     @property override string wordClass()
     {
         return "verb";
     }
}

enum WordKind : Word
{
     Unknown = null,
     Numeric = new Noun("Numeric"),
     //...
     Present = new Verb("Present"),
}

import std.stdio;
void main()
{
     string[][WordKind] dictionary;
     dictionary[WordKind.Numeric] ~= "one";
     dictionary[WordKind.Numeric] ~= "two";
     dictionary[WordKind.Present] ~= "go";
     writeln(dictionary);
}

Does this code can help you?
September 19, 2014
On Friday, 19 September 2014 at 18:49:57 UTC, Jesse Phillips wrote:
> 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."


Sorry, I'll note it.:)

>why would you want to use multiple inheritance.

I've written example with interface inherinatce.
Structs can be preferable then classes, when I want to manage them allocating manually. When you use D as "better C", powerfull struct's can be a you choise.

Multiple alias this (and therefore multiply inheritance) makes structs almost as powerful as classes.

Another my motivation of doing this work is a implementing alias this inheritance (from base class).
Situation when B can be casted to C and D, A can be casted to B and C but cannot be casted to D is wrong:

class B : C
{
   alias d this;
   D d;
}

class A : B
{
}

A a = new A;
D d = a; //NG -> OK
October 26, 2018
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.

Haha, that is funny!
1 2 3 4
Next ›   Last »