Embedded Containers

John Chapman johnch_atms at hotmail.com
Tue Dec 5 19:08:55 UTC 2017


On Tuesday, 5 December 2017 at 19:01:48 UTC, A Guy With a 
Question wrote:
> 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`)	

Your wrapping the wrong part in parentheses.

   Array!(Item!T)

It would actually be Array!(Item!(T)), but if a single type is 
specified you're allowed to omit the parentheses when 
instantiating.

>
> 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.

What other problems are you having? I did the same and it was 
fairly straightforward.



More information about the Digitalmars-d mailing list