August 16, 2021

On 8/16/21 1:59 PM, Ali Çehreli wrote:

>

On 8/15/21 1:40 AM, Daniel N wrote:

>

static struct Yay
{
      string opDispatch(string name, T...)(T vals)

I sometimes wish templates had opDispatch abilities. Then we could instantiate a template with a symbol and the the template could receive it as string just like the way it works for opDispatch. So, this could work:

  Flag!isCool isCool;

instead of today's

  Flag!"isCool" isCool;

Basically, it would still be a string parameter but the quotes need not be provided:

template Flag(string tag) {
  // ...
}

I realize that this might hide some bugs but so does opDispatch, no?

Well, aliases do work with operators, so....

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")
}

-Steve

August 16, 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

August 16, 2021

On 8/16/21 5:45 PM, Ali Çehreli wrote:

>

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

>
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

1 2
Next ›   Last »