www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - TransitiveBaseTypeTuple doesn't seemed to print the symbols as well.

reply 12345swordy <alexanderheistermann gmail.com> writes:
I expect ["__ctor", "__dtor", "toString", "toHash", "opCmp", 
"opEquals"], instead I got ["toString", "toHash", "opCmp", 
"opEquals", "Monitor", "factory"]
Care anyone explain why it is?

Source is the following:

import std.stdio;
import std.traits;

interface A
{
}


class D : A
{
     this()
     {
     }
     ~this()
     {
     }
}




void main()
{
     alias TL = TransitiveBaseTypeTuple!D;
     for(int x = 0; x < TL.length; x++)
     {
       auto b = [__traits(allMembers, TL[0])];
       writeln(b);
     }
}
Jan 10 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 10 January 2018 at 18:31:17 UTC, 12345swordy wrote:
     for(int x = 0; x < TL.length; x++)
     {
       auto b = [__traits(allMembers, TL[0])];
Simple mistake there...
Jan 10 2018
parent reply 12345swordy <alexanderheistermann gmail.com> writes:
On Wednesday, 10 January 2018 at 18:45:17 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 10 January 2018 at 18:31:17 UTC, 12345swordy 
 wrote:
     for(int x = 0; x < TL.length; x++)
     {
       auto b = [__traits(allMembers, TL[0])];
Simple mistake there...
I noticed, can't fix it cause it won't let me edit it. This auto b = [__traits(allMembers, TL[0])]; is meant to be auto b = [__traits(allMembers, TL[x])];
Jan 10 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 10 January 2018 at 19:07:46 UTC, 12345swordy wrote:
 I noticed, can't fix it cause it won't let me edit it.
OK, I'd just use foreach there anyway tho (then it actually builds!). But, hopefully once you get it running, you'll see that the base type tuple just gives the bases: it will print two lines, one for the base class Object and one for your interface A. Neither of them have constructors! It won't print the class D itself....
Jan 10 2018
parent reply 12345swordy <alexanderheistermann gmail.com> writes:
On Wednesday, 10 January 2018 at 19:26:58 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 10 January 2018 at 19:07:46 UTC, 12345swordy 
 wrote:
 I noticed, can't fix it cause it won't let me edit it.
OK, I'd just use foreach there anyway tho (then it actually builds!). But, hopefully once you get it running, you'll see that the base type tuple just gives the bases: it will print two lines, one for the base class Object and one for your interface A. Neither of them have constructors! It won't print the class D itself....
You know a equivalent template that does that?
Jan 10 2018
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 10 January 2018 at 20:38:20 UTC, 12345swordy wrote:
 You know a equivalent template that does that?
No, though you could just AliasSeq!(D, TransitiveBaseTypeTuple!D) and make it yourself. Though note that __traits(allMembers, D) already includes all members, including those from base classes too, so you might just want to use that.
Jan 10 2018