Re: How to define property type to Array!struct?
On 12/15/21 9:41 AM, Stanislav Blinov wrote: On Wednesday, 15 December 2021 at 11:36:41 UTC, Manfred Nowak wrote: On Tuesday, 14 December 2021 at 08:28:01 UTC, WebFreak001 wrote: [...] Alternatively, remove the template `()` from your `struct Header` What is the semantic sense of a template having no parameters? Although the documentation declares such a template to be syntactically correct, not a single example suggests a meaning. To add to other responses, certain features are only available for templates, such as constraints and `auto ref` parameters. Oh yeah, that reminds too -- a templated struct will have all member function attributes inferred. -Steve
Re: How to define property type to Array!struct?
On Wednesday, 15 December 2021 at 11:36:41 UTC, Manfred Nowak wrote: On Tuesday, 14 December 2021 at 08:28:01 UTC, WebFreak001 wrote: [...] Alternatively, remove the template `()` from your `struct Header` What is the semantic sense of a template having no parameters? Although the documentation declares such a template to be syntactically correct, not a single example suggests a meaning. To add to other responses, certain features are only available for templates, such as constraints and `auto ref` parameters.
Re: How to define property type to Array!struct?
On 12/15/21 6:36 AM, Manfred Nowak wrote: On Tuesday, 14 December 2021 at 08:28:01 UTC, WebFreak001 wrote: [...] Alternatively, remove the template `()` from your `struct Header` What is the semantic sense of a template having no parameters? Although the documentation declares such a template to be syntactically correct, not a single example suggests a meaning. It's just a template with no parameters, like a function with no parameters. It provides a separate namespace for items. A struct with empty template parameters is equivalent to: ```d template T() { struct T {} } ``` -Steve
Re: How to define property type to Array!struct?
On Wednesday, 15 December 2021 at 11:36:41 UTC, Manfred Nowak wrote: On Tuesday, 14 December 2021 at 08:28:01 UTC, WebFreak001 wrote: [...] Alternatively, remove the template `()` from your `struct Header` What is the semantic sense of a template having no parameters? Although the documentation declares such a template to be syntactically correct, not a single example suggests a meaning. In this case, nothing. In other cases to only compile said "object" in specific conditions.
Re: How to define property type to Array!struct?
On Wednesday, 15 December 2021 at 11:36:41 UTC, Manfred Nowak wrote: On Tuesday, 14 December 2021 at 08:28:01 UTC, WebFreak001 wrote: [...] Alternatively, remove the template `()` from your `struct Header` What is the semantic sense of a template having no parameters? Although the documentation declares such a template to be syntactically correct, not a single example suggests a meaning. For functions there is a use-case: they will not be compiled/included in the executable until they are actually instantiated once. Additionally for functions that means for libraries they aren't usually compiled into the resulting library file, unless they are used in the library themself. (only really meaningful when you don't distribute the D source or when interoping with other languages) For types similarly, if you have any template instantiations inside your templated type, they will not be instantiated or compiled, until that template is used at least once in code anywhere. So: ```d struct Header() { Appender!string name; } ``` unless Appender!string is used anywhere else in the code, that Appender struct will never be initiated, thus no member functions will be emitted or compile time will be used, until you instantiate the Header struct once.
Re: How to define property type to Array!struct?
On Tuesday, 14 December 2021 at 08:28:01 UTC, WebFreak001 wrote: [...] Alternatively, remove the template `()` from your `struct Header` What is the semantic sense of a template having no parameters? Although the documentation declares such a template to be syntactically correct, not a single example suggests a meaning.
Re: How to define property type to Array!struct?
On Tuesday, 14 December 2021 at 08:12:04 UTC, zoujiaqing wrote: My code: ```D module http.HttpRequest; import std.container; import std.array : Appender; struct HttpRequest { struct Header() { Appender!string name; Appender!string value; } string method; string uri; int versionMajor = 0; int versionMinor = 0; Array!Header headers; ubyte[] content; bool keepAlive = false; } ``` Error code: ```D source/http/HttpRequest.d(18,5): Error: struct `std.container.array.Array` does not match any template declaration ``` the problem is that your header is a template, so you need to instantiate it: ```d Array!(Header!()) headers; ``` the error message is kinda poor here. Alternatively, remove the template `()` from your `struct Header`
How to define property type to Array!struct?
My code: ```D module http.HttpRequest; import std.container; import std.array : Appender; struct HttpRequest { struct Header() { Appender!string name; Appender!string value; } string method; string uri; int versionMajor = 0; int versionMinor = 0; Array!Header headers; ubyte[] content; bool keepAlive = false; } ``` Error code: ```D source/http/HttpRequest.d(18,5): Error: struct `std.container.array.Array` does not match any template declaration ```