On Monday, 25 September 2017 at 13:20:03 UTC, Steven Schveighoffer wrote:
On 9/23/17 11:52 AM, bitwise wrote:
Is it possible to tell if two objects represented by TypeInfo's are convertible to each other?

Basically, is there a built in way to do this?

int x;
long y;
assert(typeid(x).isImplicitlyConvertibleTo(typeid(y));

I would say no. There isn't any function/data to detect that.

Keep in mind that TypeInfo is generated by the compiler, and only contains what the developers of the runtime have wanted it to contain. It's not a full-fledged reflection system.

Something like this along side TypeInfo.postblit and TypeInfo.destroy would actually be useful:

TypeInfo.cast(void* src, void** dst, TypeInfo dstType);

I wonder though...does a cast even resolve to a single function call at compile time, or is there scattered context-dependent code throughout the compiler to insert the appropriate logic?

Based on current trends though, it seems like TypeInfo.postblit/destroy may be on the chopping block...any idea?

However, you COULD build something in RTInfo that could place that inside the TypeInfo. That is what RTInfo was added for.

The comments say it's for precise GC:

https://github.com/dlang/druntime/blob/cc8edc611fa1d753ebb6a5fabbc3f37d8564bda3/src/object.d#L312-L314

Doesn't that mean my code could some day get clobbered if I put it there and precise GC is implemented?

Also, don't I need to compile a custom runtime for that?

  Thanks

Reply via email to