

C++ named operators - noobermin
https://github.com/klmr/named-operator

======
borntyping
I did much the same thing in Python a while ago:
[https://github.com/borntyping/python-
infix](https://github.com/borntyping/python-infix)

~~~
james2vegas
[https://metacpan.org/release/Sub-Infix](https://metacpan.org/release/Sub-
Infix)

------
yoklov
This is too clever to the point of being painful. (Not to mention, it has a
performance penalty for no real benefit.)

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.

~~~
nmeofthestate
Yes. This is fun, but FAR too clever. I can only speculate at the baffling
compile errors... it doesn't bear thinking about. _shudder_

------
JoshTriplett
Gah. Nice idea, but the double-operator hack seems quite painful and error
prone, especially with operators right in the middle of the precedence
hierarchy.

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.

~~~
Sharlin
* is a better choice if you need something arithmetic-like, for instance
    
    
        vector3 a, b;
        float f = a *dot* b;
        vector3 c = a *cross* c;

~~~
nikbackm
Don't you need to overload two different operators to implement these named
operators though?

~~~
krotton
No, they could equally well be two different overloads of a single operator.

------
je42
MMh. You could also this syntax for generating HTML couldn't you ?

~~~
MaulingMonkey
I present to you: XSMELL: [http://www.gamedev.net/topic/539056-c-bask-in-my-
awesomeness...](http://www.gamedev.net/topic/539056-c-bask-in-my-awesomeness/)

~~~
frozenport
Imagine if somebody did this for regex!

~~~
arcatek
Do you mean Boost Spirit?

[http://en.wikipedia.org/wiki/Spirit_Parser_Framework](http://en.wikipedia.org/wiki/Spirit_Parser_Framework)

------
EliRivers
_The following code is legal C++ and does exactly what you’d expect it to do.

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?

~~~
coldtea
> _I had no idea what that might do. No expectations at all._

Really? How is it any different than: "Hello".repeat(3).join(",");

~~~
coldpie
Mostly because the order of operations is unclear. I read it as producing
"HelloHelloHello, ". That is, repeat the previous thing three times and then
concatenate that with the string ", ". It's surprising to me that "repeat"
results in a new object with new semantics.

------
aturek
Does this increase the stack by 2 in every call?

~~~
TheCoelacanth
It's a header-only library, so it should be inlined.

------
wfunction
Terrible idea, terrible implementation, doesn't solve any actual problems...

~~~
krotton
Neither does your post. I suppose it was just written for fun or learning
experience.

