Deduct and return class type
Виталий Фадеев
vital.fadeev at gmail.com
Sat Jan 23 05:54:09 UTC 2021
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;
this( T data )
{
this.data = data;
}
// data usage...
}
}
auto listFactory( T )( T data )
{
return new List!( T )( data );
}
void main()
{
string[] extensions = [ ".d", ".di" ];
auto list = listFactory( extensions );
//auto list = new List( extensions );
}
source: https://run.dlang.io/is/y167tu
But, how to create class instance with type deduction in usual
way ?
auto list = new List( extensions );
More information about the Digitalmars-d-learn
mailing list