On Tuesday, 16 June 2020 at 13:31:49 UTC, Atila Neves wrote:

<snip>

With a few changes, yes (added missing semicolons, changed IGeometry to Geometry in `measure`, passed the current module so tardy can find the UFCS functions, added `@safe pure` to the UFCS functions:

[...]

void main() {
    auto r = Rect(3.0, 4.0);
    auto c = Circle(5.0);

    Geometry.create!__MODULE__(r).measure;
    Geometry.create!__MODULE__(c).measure;
}

IMO this can be done more elegantly by separating out the code that looks up methods in the current module from the code that does the actual type erasure.

A while ago, I collaborated briefly with Adam Kowalski from the Dlang discord server on some code to emulate C++-style argument-dependent lookup in D. Using that code, your example above would be written:

    Geometry.create(r.extended).measure;
    Geometry.create(c.extended).measure;

Here's a gist with the code, along with a small example:

https://gist.github.com/pbackus/0a70419eb8bece52f3a08edfe7b6019b

If anyone thinks it's worthwhile, I can toss this up on Dub. Personally, I've never had much use for it in my own projects.

Reply via email to