The possibility of a DLang dynamic transfer class type and a member type.

Basile B. b2.temp at gmx.com
Fri Nov 15 09:27:27 UTC 2019


On Friday, 15 November 2019 at 09:06:35 UTC, zoujiaqing wrote:
> On Thursday, 14 November 2019 at 21:03:28 UTC, Paul Backus 
> wrote:
>> On Thursday, 14 November 2019 at 08:47:15 UTC, zoujiaqing 
>> wrote:
>>> [...]
>>
>> You can do something pretty similar with TypeInfo:
>>
>> void main()
>> {
>>     TypeInfo_Class class1;
>>     TypeInfo_Class class2;
>>
>>     class1 = typeid(A);
>>     class2 = typeid(B);
>>
>>     auto obj1 = class1.create;
>>     auto obj2 = class2.create;
>>
>>     if (true)
>>     {
>>         {
>>         	Base obj = cast(Base) obj1;
>>         	writeln(obj.count()); // 1
>>         }
>>         {
>>         	Base obj = cast(Base) obj2;
>>         	writeln(obj.count()); // 2
>>         }
>>     }
>> }
>
> I want get property type, like this:
>
> auto testType1 = A.a;
> auto testType2 = B.a;
>
> if (testType1 is testType2)
> {
>     writeln("yes");
> }

In D we rather do these kind of stuff statically, using template 
parameters and constraints, e.g as constraint 
if(__traits(hasMember)).


More information about the Digitalmars-d mailing list