[Issue 3968] Some way to do certain implicit casts with operator overloading

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 1 07:05:28 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=3968

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |simen.kjaras at gmail.com
         Resolution|---                         |FIXED

--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
This works today:

struct Foo {
    int x;
    int opCast(T:int)() {
        return this.x;
    }
    alias fn = opCast!size_t;
    alias fn this;
}
unittest {
    Foo f = Foo(5);
    auto a1 = new int[cast(int)f]; // OK
    auto a2 = new int[f];          // Also OK
}

The syntax 'alias opCast!size_t this;' fails to compile, citing 'no identifier
for declarator opCast!size_t'.

--


More information about the Digitalmars-d-bugs mailing list