Is it possible to use tokens as template parameters?
Steven Schveighoffer
schveiguy at gmail.com
Tue Aug 17 01:09:59 UTC 2021
On 8/16/21 5:45 PM, Ali Çehreli wrote:
> 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;
Well, I mean it's just `.` instead of `!`. What's the big deal? ;)
Honestly, I didn't expect this to work when I tried it, but I did know
that aliases do work with operator overloads (a hugely cool feature).
-Steve
More information about the Digitalmars-d
mailing list