On Wednesday, 15 February 2017 at 10:59:25 UTC, Kagamin wrote:
On Wednesday, 15 February 2017 at 03:40:32 UTC, Mike Parker wrote:
My specific use case is a binding to a C library that makes use of specific types from X11, Wayland and elsewhere.

If X11.Foo is implicitly convertible to forward reference Foo and forward reference Foo is implicitly convertible to Wayland.Foo, then X11.Foo is implicitly convertible to Wayland.Foo.

Not quite what I meant. I want to use X11 types without forcing the user to choose between Tom's X11 bindings and Jerry's. The user should be able to use either. Ditto for multiple Wayland bindings. So, for example:

version(UseX11) {
    struct Display;
    alias EGLNativeWindowType = Display*;
}
else version(UseWayland) {
    struct wl_display;
    EGLNativeWindowType = wgl_display*;
}

Then when compiling with UseX11, the user can import tom.x11 or jerry.x11, whichever he prefers.

It's so tantalizingly close to being possible. My earlier example compiles and runs when using type inference:

module ec3;
void main() {
    import ec1, ec2;
    auto f = newFoo(30);
    printFoo(f);
}

My intuition is screaming at me. If this works, then shouldn't it also work when I declare the type myself?

And if I add `alias MyFoo = Foo*` to ec1, then the first error, the one about conflicts, goes away, but I still get the latter two errors related to the function call. Why? I'm still returning an ec2.Foo* and assigning it to an ec1.Foo*. An alias is just a synonym. The types haven't changed.


Reply via email to