C++ named operators
github.com
github.com
I think I'd just give up and go home if I ever saw this in code I had to maintain.
EDIT: Actually, looking more closely, I guess there isn't a performance penalty (I saw back_inserter and assumed it was required for the implementation). That said, I still think it's far too clever.
This might be one of the few rare justifications for overloading the comma operator, for syntax similar to that of Haskell's backquote:
arbitrary+expr ,foo, arbitrary-expr
Then the ,foo, would get processed last, letting the expressions evaluate first, which matches the semantics of Haskell's infixing backquotes (lowest precedence by default).Even then, though, that would get ugly in a hurry when mixed with function calls, requiring parentheses for sanity.
Overloading the operator removes this sequence point. Too sketchy for my blood.
Some prior art: http://www.gamedev.net/blog/2/entry-19599-bad-code-here/
vector3 a, b;
float f = a *dot* b;
vector3 c = a *cross* c;auto result = "Hello" <repeat> 3 <join> ", ";
I had no idea what that might do. No expectations at all. Is this an attempt to write language X in language Y?
Really? How is it any different than: "Hello".repeat(3).join(",");
I read it as "repeat the string Hello thrice and then add a comma and space". It's not really clear that "repeat" returns a list.
A C# equivalent would be:
String.Join(", ", Enumerable.Repeat("Hello", 3))
Here it's easier to see that Repeat returns an Enumerable object.Using an Extension Method, it's easy to see how someone could mistake the output: