Thread overview
Embedded interfaces with generic members
Dec 05, 2017
Ali Çehreli
December 05, 2017
The following doesn't appear to be valid syntax. Array!Item!T

I get the following error:

"multiple ! arguments are not allowed"	

Which is ok...I get THAT error, however, this does not work either:

alias Items(T) = Array!Item(T);

This gives me the error:

Error: function declaration without return type. (Note that constructors are always named `this`)	

Item is defined as follows:

interface Item(T)
{
   @property
   T member();
}

That part compiles fine. However, even when I remove the aliasing, I can't import this interface. I get "Error: undefined identifier 'Item'"

I'm not quite sure I understand how to create a generic container interface or class in D. Half of how I expect it to work works, but the other half doesn't. The docs aren't too helpful. I'm not sure if it's a case where there's just too much to go through or if what I'm trying to do isn't really covered. Essentially I'm trying to create an array of this type 'Item' that has some generic members. I think people who come from C# will kind of get what I'm trying to do here, because I'm trying to port C# code.
December 05, 2017
On 12/05/2017 11:07 AM, A Guy With a Question wrote:
> The following doesn't appear to be valid syntax. Array!Item!T

You can ommit the template argument list parenteses only for single symbols.

Starting with the full syntax:

  Array!(Item!(T))

Since Item!(T) uses a single symbol, T, you can remove the parenteses from that one:

  Array!(Item!T)

The following compiles:

import std.container.array;

struct Item(T) {
}

void main() {
    alias T = int;
    auto a = Array!(Item!T)();
}

Ali

December 05, 2017
On Tuesday, 5 December 2017 at 19:27:37 UTC, Ali Çehreli wrote:
> On 12/05/2017 11:07 AM, A Guy With a Question wrote:
> > The following doesn't appear to be valid syntax. Array!Item!T
>
> You can ommit the template argument list parenteses only for single symbols.
>
> Starting with the full syntax:
>
>   Array!(Item!(T))
>
> Since Item!(T) uses a single symbol, T, you can remove the parenteses from that one:
>
>   Array!(Item!T)
>
> The following compiles:
>
> import std.container.array;
>
> struct Item(T) {
> }
>
> void main() {
>     alias T = int;
>     auto a = Array!(Item!T)();
> }
>
> Ali

yup that was the issue.