www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - string to type

reply =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
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.
Feb 24 2021
parent reply =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Thursday, 25 February 2021 at 06:51:11 UTC, Виталий Фадеев 
wrote:
 Say, please,
 how to convert string to type ?

 [...]
Simple version of this question is: string t = "X"; mixin t!(); // <-- HERE TROUBLE
Feb 24 2021
parent =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Thursday, 25 February 2021 at 06:53:28 UTC, Виталий Фадеев 
wrote:
 On Thursday, 25 February 2021 at 06:51:11 UTC, Виталий Фадеев 
 wrote:
 Say, please,
 how to convert string to type ?

 [...]
Simple version of this question is: string t = "X"; mixin t!(); // <-- HERE TROUBLE
I was stupid. Solution is: mixin ( "mixin " ~ IFACE.stringof[ 1 .. $ ] ~ "!();" ); Thanks!
Feb 24 2021