On Wednesday, 26 March 2014 at 19:29:49 UTC, Artur Skawina wrote:
On 03/07/14 20:22, Frustrated wrote:
On Friday, 7 March 2014 at 09:10:45 UTC, John Colvin wrote:
functions introduced through mixin templates do not take part in overload resolution when an overload exists outside the mixin. It's a common annoyance, I can't remember if there's a good reason for it.


This seems to be the problem. The mixin thinks they are the same function so it doesn't insert it. I guess it just looks at the name rather than the complete signature. Would be real nice if that wasn't the case or if one could chose the behavior. I can see in some cases it being nice to have the current behavior but not all(specifically talking about overloads).


You can explicitly add the function(s) to the overload set, ie

   mixin template some_mixin_templ() {
      void f() {}
   }

   struct S {
      mixin some_mixin_templ blah;

      void f(int) {}
alias f = blah.f; // add the one(s) from the mixin template
   }

or use a string mixin (which is less problematic inside a /mixin/ template):

   mixin template some_mixin_templ(string CODE="") {
      void f() {}
      mixin (CODE);
   }

   struct S {
      mixin some_mixin_templ!q{
         void f(int) {}
      };
   }

artur

This is not really any better than just using a string mixin directly. You have to create a named mixin then create the aliases. In your example, you know the function being mixed in so it is easy. In my case, the function name was generated by a string mixin. So I'd basically have to have to mixins, one to generate the function itself and the other to generate the aliases, then I've have to call them both in the struct. Much worse than just passing the typeof(this) to the string mixin.

The only way it could work is if I could use the alias inside the template mixin and it all work out. In any case, it's a very convoluted way to achieve what I want(which is simply not having to pass typeof(this) to the string mixin).


Reply via email to