Should we add `a * b` for vectors?
jmh530
john.michael.hall at gmail.com
Fri Oct 6 21:05:05 UTC 2017
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");
}
More information about the Digitalmars-d
mailing list