5 ms·
I'd really like it if they added D's uniform function call syntax to C++ (http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394 http://www.drdobbs.c
by byuu 12y ago
I'd really like it if they added D's uniform function call syntax to C++ (http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394 http://www.drdobbs.com/cpp/uniform-function-call-syntax/2327...). Then this code could be:
auto r = numbers().where([](int x) { return x > 2; }).select([](int x) { return x * x; });
Without the need and potential ambiguity that arises from overloading the pipe operator, you'd just use simple free functions instead and it'd just work.
- paxcoder 12y agoPotentially ambiguous, but I assume worth it?
- pfultz2 12y agoIn practice, I've yet to see a problem.
- byuu 12y agoBy ambiguous, I mean that operator|'s precedence is very different than operator.'s (std::operator<< has similar issues); which could lead to surprises if you don't have the precedence tables memorized. operator. is at the optimal precedence for method chaining, and has well understood behavior, so I think it'd be preferred over hijacking things like the bitwise-or operator.
- paxcoder 12y agoHeh, didn't even notice that you mentioned ambiguity too. I was refering to the D's version with the dot operator: A programmer needs to differentiate between function calls and method calls. I wonder which ambiguity @pfultz2 was referring to. But now that you mention it, an operator (such as pipe) with a lower precedence could actually be useful and spare having to jump back in code to open brackets.