On Friday, 6 October 2017 at 20:36:47 UTC, Jonathan M Davis wrote:

It forces them to actually be designed with the type and be easily located with the type. Would you want a programmer to be able to go and implement opBinary!"+" for strings? I sure wouldn't. And I don't want anyone doing that for user-defined types that they didn't define either.


Tangentially (I admit), there's nothing stopping you from below:

struct MyString
{
    string mystring;
    alias mystring this;
    string opBinary(string op)(string rhs)
        if(op == "+")
    {
        return mystring ~ rhs;
    }
}

void main()
{
    MyString x = MyString("foo");
    string y = "bar";
    auto z = x + y;
    assert(z == "foobar");
}

Reply via email to