How to define property type to Array!struct?
WebFreak001
d.forum at webfreak.org
Wed Dec 15 12:25:30 UTC 2021
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.
More information about the Digitalmars-d-learn
mailing list