Re: Deduct and return class type

2021-01-23 Thread Виталий Фадеев via Digitalmars-d-learn
On Saturday, 23 January 2021 at 19:19:29 UTC, Paul Backus wrote: On Saturday, 23 January 2021 at 07:17:38 UTC, Виталий Фадеев wrote: Where source ? Where deduction implementation ? Here: https://github.com/dlang/dmd/blob/v2.095.0/src/dmd/dtemplate.d#L1308 Thank!

Re: Deduct and return class type

2021-01-23 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 23 January 2021 at 07:17:38 UTC, Виталий Фадеев wrote: Where source ? Where deduction implementation ? Here: https://github.com/dlang/dmd/blob/v2.095.0/src/dmd/dtemplate.d#L1308

Re: Deduct and return class type

2021-01-22 Thread Виталий Фадеев via Digitalmars-d-learn
On Saturday, 23 January 2021 at 05:54:09 UTC, Виталий Фадеев wrote: On Saturday, 23 January 2021 at 05:39:18 UTC, Виталий Фадеев wrote: Context: data + GUI List Goal: auto list = new List( data ); I want 'this( T )( T data )' deduction: class A( T ) { this( T )( T

Re: Deduct and return class type

2021-01-22 Thread tsbockman via Digitalmars-d-learn
On Saturday, 23 January 2021 at 05:54:09 UTC, Виталий Фадеев wrote: auto listFactory( T )( T data ) { return new List!( T )( data ); } This is the correct way to do it in D; it's annoying, I know. (Personally, I usually shorten `listFactory` to just `list` to make the

Re: Deduct and return class type

2021-01-22 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 23 January 2021 at 05:54:09 UTC, Виталий Фадеев wrote: But, how to create class instance with type deduction in usual way ? auto list = new List( extensions ); You can't; there's no type deduction for constructors.

Re: Deduct and return class type

2021-01-22 Thread Виталий Фадеев via Digitalmars-d-learn
On Saturday, 23 January 2021 at 05:39:18 UTC, Виталий Фадеев wrote: Context: data + GUI List Goal: auto list = new List( data ); Of course, we can use 'factory': import std.stdio; template List( alias T ) { class List { T data;

Deduct and return class type

2021-01-22 Thread Виталий Фадеев via Digitalmars-d-learn
Context: data + GUI List Goal: auto list = new List( data ); Concept: class is created in the usual way : new List( data ) store inside the class: T data; type T deducted : ( T )( T data ) Tried way: template List( T ) { class