Deduct and return class type

Виталий Фадеев vital.fadeev at gmail.com
Sat Jan 23 05:39:18 UTC 2021


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 List
         {
             T data;

             this( T data )
             {
                 this.data = data;
             }


             // data usage...
         }
     }


     void main()
     {
         string[] extensions = [ ".d", ".di" ];

     	auto list = new List( extensions );
     }


     Source: https://run.dlang.io/is/Bw2zHB

Question:
     How to implement on D beauty clean flexible code ?
     like a:
         auto list = new List( data );

     How to return from 'List( data )' class type ?



More information about the Digitalmars-d-learn mailing list