Multiple alias this is coming.
IgorStepanov via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Fri Sep 19 12:08:32 PDT 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?
More information about the Digitalmars-d-announce
mailing list