www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.container.array: Error: unable to determine fields of Test because

reply Tobias Pankrath <tobias pankrath.net> writes:
My Problem:

--- (https://run.dlang.io/is/CfLscj)
import std.container.array;
import std.traits;

struct Test
{
    Test[] t;
}

struct Test2
{
    Array!Test2 t;
}

int main()
{
	return FieldTypeTuple!Test.length + FieldTypeTuple!Test2;
}
---

I've found https://issues.dlang.org/show_bug.cgi?id=19407 but I 
am not using separate compilation, just `dmd test.d`.

I want to have a tree structure like

---
struct S
{
     S[] children;
}
---

but I do not want to rely on the GC and thus wanted to use a 
custom array type. What's the best way to do this?
Oct 31 2019
parent reply user1234 <user1234 12.de> writes:
On Thursday, 31 October 2019 at 12:29:28 UTC, Tobias Pankrath 
wrote:
 My Problem:

 --- (https://run.dlang.io/is/CfLscj)
 import std.container.array;
 import std.traits;

 struct Test
 {
    Test[] t;
 }

 struct Test2
 {
    Array!Test2 t;
 }

 int main()
 {
 	return FieldTypeTuple!Test.length + FieldTypeTuple!Test2;
 }
 ---

 I've found https://issues.dlang.org/show_bug.cgi?id=19407 but I 
 am not using separate compilation, just `dmd test.d`.

 I want to have a tree structure like

 ---
 struct S
 {
     S[] children;
 }
 ---

 but I do not want to rely on the GC and thus wanted to use a 
 custom array type. What's the best way to do this?
Try struct S { S*[] children; } because otherwise when you declare the array the compiler has not finished the semantic ana of S.
Oct 31 2019
next sibling parent user1234 <user1234 12.de> writes:
On Thursday, 31 October 2019 at 12:37:55 UTC, user1234 wrote:
 On Thursday, 31 October 2019 at 12:29:28 UTC, Tobias Pankrath 
 wrote:
 [...]
Try struct S { S*[] children; } because otherwise when you declare the array the compiler has not finished the semantic ana of S.
so S size is not known while S* size is known as it's a pointer
Oct 31 2019
prev sibling parent Tobias Pankrath <tobias pankrath.net> writes:
On Thursday, 31 October 2019 at 12:37:55 UTC, user1234 wrote:
 struct S
 {
      S*[] children;
 }

 because otherwise when you declare the array the compiler has 
 not finished the semantic ana of S.
--- struct Test { Test[] t; } --- Works today. Putting pointers into the container (and thus having another indirection) is not an option, though.
Oct 31 2019