On Friday, 24 February 2023 at 14:22:17 UTC, user1234 wrote:
you can break using `goto`, restore `static` everywhere, and using local introspection determine whether the result exists.

```d
struct Bar
{
        @("hello") int t;
}

static bool hasAttribute(alias F, T)()
{
        static foreach (a; __traits(getAttributes, F))
        {
                static if (is(typeof(a) : T))
                {
                        enum result = true;
                        goto L0;
                }
        }
        L0:
        static if (is(typeof(result)))
                return result;
        else
                return false;
}

void main()
{
        import std.stdio;

        writeln(hasAttribute!(Bar.t, string));
}
```

Unfortunately there is a serious bug in this code. Take a look at what happens when you try it with this `struct Bar`:

```d
struct Bar
{
        @("hello") @("goodbye") int t;
}
```

Reply via email to