static map as a type function

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Sep 25 13:33:29 UTC 2020


On 9/24/20 3:00 PM, Adam D. Ruppe wrote:
> But maybe you could still have one template returning that and just 
> using typeinfo for its internal intermediate calculations.

Yah, looking at the ilk of std.meta and std.traits it seems that the 
more complicated items in there would be done like this:

1. Convert the type(s) into TypeInfo(s)
2. Use everyday algorithms (including std) to carry computation
3. If needed, convert the result(s) back into TypeInfo(s)

BTW, this process is akin to reification: 
https://en.wikipedia.org/wiki/Reification_(computer_science).

For TypeInfo objects, by far the most frequent operations will be to 
copy them around and to compare them for equality. Then there are a few 
more things necessary:

*    add a qualifier to a type
*    strip a qualifier from a type
*    strip all qualifiers from a type
*    are two types equal?
*    is type1 implicitly convertible to type2?
*    if function, give me the return type and the parameter types

So we'd need to add these primitives to TypeInfo. They all must be 
computable during compilation:

class TypeInfo {
     ... existing stuff ...
     TypeInfo addQualifier(string qual);
     TypeInfo stripQualifier(string qualifier);
     TypeInfo stripAllQualifiers();
     bool implicitlyConvertsTo(Typeinfo another);
     TypeInfo functionReturn(); // null if not a function
     Typeinfo[] functionParameters(); // null if not a function
}

This and a solution to https://issues.dlang.org/show_bug.cgi?id=9945 
would impart tremendous power.


More information about the Digitalmars-d mailing list