static map as a type function

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Sep 24 05:51:30 UTC 2020


On Thu, Sep 24, 2020 at 01:13:49AM -0400, Andrei Alexandrescu via Digitalmars-d wrote:
[...]
> Was looking at this example thinking, if only we had an object
> available for each type. And then it struck me - we already do. It's
> typeid. For each type T, typeid(T) yields an object (of type class
> TypeInfo) that can be copied, compared etc.

+1.  I've mentioned this before in one of Stefan's threads.  Basically,
to promote types to first-class citizen status, all we need to do is to
treat typeid specially at compile-time.  At compile-time, typeid becomes
something like a glorified alias to the type itself, such that it can be
manipulated, passed around, interrogated, etc..  At runtime, typeid
becomes the familiar RTTI object.


[...]
> * This could work with no change to the language definition. All
> that's needed to get lift is make TypeInfo values usable during
> compilation.

Or treat typeid specially at compile-time, as a compile-time object not
necessarily tied to TypeInfo (but "collapses" into TypeInfo at runtime).


T

-- 
There are 10 kinds of people in the world: those who can count in binary, and those who can't.


More information about the Digitalmars-d mailing list