__typeid

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Aug 2 19:54:37 UTC 2020


On 8/1/20 10:47 PM, Paul Backus wrote:
> On Saturday, 1 August 2020 at 16:12:58 UTC, Andrei Alexandrescu wrote:
>> * An important use of __typeid will be to implement Variant "the right 
>> way". Using the __typeid instead of the unsightly pointer to handler 
>> function in Variant would go a long way toward simplifying it. the 
>> __typeid API would be therefore geared toward the needs of that type. 
>> I've come to the realization that that type is essential for the use 
>> of D in dynamic contexts. I'd name that type Box, put it in druntime, 
>> and make it available to Das Besser C.
> 
> In other languages, a Box is a wrapper that turns a value type into a 
> reference type. [1][2][3] It is not a container for a single 
> dynamically-typed value--in fact, its value is typically statically-typed.
> 
> Most languages do not have a type like the one D currently calls 
> Variant, but in those that do, the most widely-accepted name seems to be 
> Any. [4][5]
> 
> [1] https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html
> [2] https://doc.rust-lang.org/std/boxed/struct.Box.html
> [3] 
> https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/boxing-and-unboxing 
> 
> [4] https://en.cppreference.com/w/cpp/utility/any
> [5] https://www.scala-lang.org/api/current/scala/Any.html

Any is great.


More information about the Digitalmars-d mailing list