On Thursday, 10 September 2020 at 13:14:47 UTC, drug wrote:
Just a thought - couldn't you use classes for this? Get an UDA
and check if it is a descendant of the specific class.
Yes, I did wonder about that, but it doesn't allow all the
inference that I'm looking for. For example:
class First
{
enum A;
enum B;
}
class Second : First
{
}
@(Second.A)
struct MySecond
{
}
import std.traits : hasUDA;
static assert(hasUDA!(MySecond, Second.A)); // OK!
static assert(hasUDA!(MySecond, First.A)); // OK!
static assert(hasUDA!(MySecond, Second)); // fails
static assert(hasUDA!(MySecond, First)); // fails
It's obvious _why_, of course, given how I set the above up. And
this contrasts with what one can do with enums:
enum Something { A, B }
@(Something.A)
struct MySomething { }
import std.traits : hasUDA;
static assert(hasUDA!(MySomething, Something.A)); // OK!
static assert(hasUDA!(MySomething, Something)); // OK!
... where I can check for the enum specialization _or_ the
general enum type and have things just work.
I'm looking, ideally, to be able to do both. I did try something
like:
enum First { A, B }
enum Second : First { A = First.A, B = First.B }
... but that doesn't work. Hence why I thought it might be worth
making a forum post.