Comment #0 by john.michael.hall — 2020-08-05T20:36:23Z
The code below fails to compile because the template parameter U is in both is statements in isFoo. The code for isFoo2, which changes the U in the second is statement, compiles without error.
I see nothing in the specification that would suggest that isFoo should fail to compile, though I may have missed it. Nevertheless, there is a workaround.
struct Foo(T)
{
T x;
}
struct Foo(T, U)
{
T x;
}
enum bool isFoo(T) = is(T : Foo!(U), U) || is(T : Foo!(U, V), U, V);
enum bool isFoo2(T) = is(T : Foo!(U), U) || is(T : Foo!(W, V), W, V);
void main()
{
static assert(isFoo!(Foo!(int)));
static assert(isFoo!(Foo!(int, int)));
static assert(isFoo2!(Foo!(int)));
static assert(isFoo2!(Foo!(int, int)));
}
Comment #1 by robert.schadek — 2024-12-13T19:10:39Z