digitalmars.D.learn - Embedded interfaces with generic members
- A Guy With a Question (26/26) Dec 05 2017 The following doesn't appear to be valid syntax. Array!Item!T
- =?UTF-8?Q?Ali_=c3=87ehreli?= (16/17) Dec 05 2017 You can ommit the template argument list parenteses only for single symb...
- A Guy With a Question (2/20) Dec 05 2017 yup that was the issue.
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
On 12/05/2017 11:07 AM, A Guy With a Question wrote:The following doesn't appear to be valid syntax. Array!Item!TYou 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
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:yup that was the issue.The following doesn't appear to be valid syntax. Array!Item!TYou 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