Reimplementing the bulk of std.meta iteratively

Steven Schveighoffer schveiguy at gmail.com
Sun Sep 27 02:30:37 UTC 2020


On 9/26/20 6:48 PM, Andrei Alexandrescu wrote:
> A possibly angle here is to save that information in runtime format, 
> i.e. reify the inheritance/convertibility relationship.

thinking it through...

All basic types have well-defined relationships that can be figured out 
using a big statically generated switch thing.

Enums can be converted to their bases, and whatever they can convert to.

Structs can be converted to their alias-this parameter.

Classes can also have an alias this, AND a set of base types.

Arrays and pointers can convert in certain cases to base types.

And, multiply all this by mutability changes (convert to const for 
things with references, and convert to anything for value types).

So for each type, you could generate a list of types that it can convert 
to. Then on each comparison, search for the target type in the list, and 
if you find it, return true.

I can't imagine this is going to be efficient. We might be able to 
factor out the const changes. But it still leaves a big list of things. 
Honestly, I don't know if the compiler does it in a more efficient way 
than searching through a list.

So it's definitely doable, I just don't know if we would want to do it, 
or if the complication of the resulting code is worth it. is(a : b) is 
just soooo much easier! And I think this is one aspect that type 
functions allow.

If there were a way to go back to type-land in the middle of 
runtime-at-ctfe-land, even if you had to define it in a restrictive way, 
then it might be much more palatable.

-Steve


More information about the Digitalmars-d mailing list