www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Embedded interfaces with generic members

reply A Guy With a Question <aguywithanquestion gmail.com> writes:
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 


Dec 05 2017
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Dec 05 2017
parent A Guy With a Question <aguywithanquestion gmail.com> writes:
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.
Dec 05 2017