string to type

Виталий Фадеев vital.fadeev at gmail.com
Thu Feb 25 06:51:11 UTC 2021


Say, please,
how to convert string to type ?

Is:
     interface IX
     {
         //
     }

     mixin template X()
     {
         //
     }

     // Mixin templates to class.
     //   Scan class interfaces, then mix
     mixin template Members()
     {
         alias T = typeof( this );

         static
         foreach ( IFACE; InterfacesTuple! T )
         {
             pragma( msg, IFACE );
             pragma( msg, IFACE.stringof[ 1 .. $ ] );

             static
             if ( IFACE.stringof.length > 1 && IFACE.stringof[ 1 
.. $ ] )
             {
                 mixin ( IFACE.stringof[ 1 .. $ ] )!(); // <-- 
HERE TROUBLE
             }
         }
     }

     class A : IX
     {
         mixin Members!();
     }

Want:
     // Mixin template
     mixin IFACE.stringof[ 1 .. $ ] !();

Got:
     Compilation error: "declaration expected"

source: https://run.dlang.io/is/smFaWc

Help wanted.



More information about the Digitalmars-d-learn mailing list