On 05.09.2016 15:35, Andrei Alexandrescu wrote:
On 9/5/16 11:43 AM, Timon Gehr wrote:
On 05.09.2016 06:05, Manu via Digitalmars-d wrote:
An algorithm that calls a function on
some T it receives just wants to look near the T; UFCS functions will
be there.

I agree with your post except for this.

In general there could be four modules: one defines the type, one
defines the UFCS function, one defines the generic algorithm, and the
last one imports the former three. The problem is that D has no standard
way to make them work together.

Do you think there should?

Probably. This kind of pattern has been very successful in other languages.

And if so, what would the algorithm be? --
Andrei

This is a good question. I'm not sure yet what the best solution is.

One hacky way is to provide a mixin template to create a wrapper type within each module that needs it, with std.typecons.Proxy. Proxy picks up UFCS functions in addition to member functions and turns them into member functions. But this leads to a lot of template bloat, because callers that share the same added UFCS functions don't actually share the instantiation. Also, it only works one level deep and automatically generated Wrapper types are generally prone to be somewhat brittle.

There is always the default option of requiring the user to create the Wrappers manually, but that's a lot of boilerplate. (Other languages can do analogous things in a very streamlined fashion, by not supporting arbitrary template constraints.)
      • Re: ADL John Colvin via Digitalmars-d
      • Re: ADL Walter Bright via Digitalmars-d
      • Re: ADL Walter Bright via Digitalmars-d
    • Re: ADL Andrei Alexandrescu via Digitalmars-d
    • Re: ADL Andrei Alexandrescu via Digitalmars-d
      • Re: ADL Manu via Digitalmars-d
      • Re: ADL Timon Gehr via Digitalmars-d
        • Re: ADL Andrei Alexandrescu via Digitalmars-d
          • Re: ADL deadalnix via Digitalmars-d
          • Re: ADL Timon Gehr via Digitalmars-d
          • Re: ADL Guillaume Boucher via Digitalmars-d
    • Re: ADL Ethan Watson via Digitalmars-d
      • Re: ADL Walter Bright via Digitalmars-d
        • Re: ADL Ethan Watson via Digitalmars-d
  • Re: ADL Tobias Müller via Digitalmars-d
    • Re: ADL Andrei Alexandrescu via Digitalmars-d
      • Re: ADL Tobias M via Digitalmars-d
        • Re: ADL Andrei Alexandrescu via Digitalmars-d
          • Re: ADL Tobias M via Digitalmars-d
          • Re: ADL Andrei Alexandrescu via Digitalmars-d

Reply via email to