Is it possible to use tokens as template parameters?

Ali Çehreli acehreli at yahoo.com
Mon Aug 16 21:45:16 UTC 2021


On 8/16/21 12:37 PM, Steven Schveighoffer wrote:

 > ```d
 > import std.typecons;
 >
 > struct S
 > {
 >      alias opDispatch(string foo) = Flag!foo;
 > }
 >
 > void main()
 > {
 >      S.bar x;
 >      import std.traits;
 >      pragma(msg, fullyQualifiedName!(typeof(x))); //
 > std.typecons.Flag!("bar")
 > }
 > ```

Me no understand. :) I see it as an example of how opDispatch is 
privileged. It nicely parses a token and provides it as a string. 
Templates don't have that. I want to be able say

   std.typecons.Flag!foo f;

instead of

   std.typecons.Flag!"foo" f;

Ali



More information about the Digitalmars-d mailing list