Thread overview
Testing presence of member functions with same name but different signature.
Feb 06, 2014
Matthias Walter
Feb 06, 2014
Timon Gehr
Feb 08, 2014
Matthias Walter
February 06, 2014
Hi,

I realized the following behavior and want to ask whether this is expected behavior and if yes, I'd like to know a reason.

The check of MyClass.func(MyClass.A) and MyClass.func(MyClass.B) in the
main() function succeeds, but the alias line *in* the class definition
fails with "template instance main.ConditionalUse!(MyClass) does not
match template declaration ConditionalUse(T) if (hasFuncs!T)".

If I rename func to funcA and funcB (making the name unambiguous), both
checks succeed.

Is this a bug?

template hasFuncs(T) // Checks presence of T.func(T.A) and T.func(T.B)
{
  enum bool hasFuncs =
      is(typeof((T t, T.A a){ t.func(a); }))
    &&
      is(typeof((T t, T.B b){ t.func(b); }));
}

struct ConditionalUse(T) if (hasFuncs!T) { }

// This line fails with
//
// template instance main.ConditionalUse!(MyClass) does not
// match template declaration ConditionalUse(T) if (hasFuncs!T)

class MyClass
{
  struct A {}
  struct B {}

  alias ConditionalUse!MyClass Foo;

  void func(A a) { }
  void func(B b) { }
}

int main(char[][] args)
{
  static assert(hasFuncs!MyClass); // This assert is fine.
  return 0;
}

Best regards,

Matthias
February 06, 2014
On 02/06/2014 10:32 PM, Matthias Walter wrote:
> Is this a bug?

Yes.
February 08, 2014
On 02/06/2014 10:44 PM, Timon Gehr wrote:
> On 02/06/2014 10:32 PM, Matthias Walter wrote:
>> Is this a bug?
> 
> Yes.

Okay, added a ticket: http://d.puremagic.com/issues/show_bug.cgi?id=12102