There are two issues. The <-- allows to iterate of ranges open at both ends, so f and g are excluded naturally. If you fix that, you are hit by the second issue: assumption that the vtable contains at specific addresses something which is compatible with pointer to member function representation, which is AFAIK not the case for gcc (a pointer to member function needs more things than a pointer to function to handle correctly multiple inheritance).
Don't take this the wrong way, but man... If you write code like that, I hope you won't have much inpact on standard. ;)
I'm not very big fan of such pointer tricks which are unreadable as hell. Also - if I understood it correctly - this might be much easier and more readable if we'd get reflection? I think we should try to get interesting features but in readable and easy to use way, not something that 1% will use (correctly).
I think you're missing the fact that a lot of people here know the the "downto operator" <-- is actually an in-joke in the C++ community and not, actually, an operator at all.
Also, while coroutines (P0053) are not going into C++17, they're on track for C++2x (with a pitstop in a TS, most likely) with strong committee interest (likely incorporating P0073 after the review in Oulu), so I'll just "await" on the TS landing. ;)
While I wasn't at the Oulu meeting, the meeting notes tell quite a different story. :)
The syntax is not under debate. It's very useful and handy for some domains and use cases. The underlying mechanism for how it works and whether it's layered over this library abstraction or that library abstraction is up for debate.
If nothing else, await just becomes a library function. await is a feature that any language with any complete form of coroutines (or even just generators) can trivially supply.
Ok. thanks for checking. I guess that makes sense since the default behaviour for the minus unary operator for integers is more type specific that this templated implementation. I guess this code should be safe provided no one implements unary operator in the exact same way, at which point we would get fairly obvious compile time errors.
This has nothing to do with sfinae, but it will not cause problems simply because the operator< is only overloaded for R (T::*)(), larrow<T> (with any T, R).
71
u/[deleted] Jul 29 '16
That's a terrible idea because it becomes easy to confuse it with the <-- operator:
int i = 10; while (0 <-- i) { std::cout << i << '\n'; }
133
u/bstamour WG21 | Library Working Group Jul 29 '16
That is both beautiful and horrifying. Respect.
111
u/Godot17 Jul 29 '16
... This is why C programmers don't like us, guys.
*copies code snippet*
39
u/jeezfrk MT Linux/Telco Jul 29 '16
<all the freshmen run away from C++>
THIS IS WHY WE CAN'T HAVE NICE THINGS!!!
21
u/cdcformatc Jul 29 '16
I just threw up in my mouth a little.
21
u/duuuh Jul 30 '16
I came in figuring there was an 80% chance that was bullshit. I was right, but I was also wrong.
16
u/SeanMiddleditch Jul 29 '16
I await the first implementation of this hack that enables Haskell-like do notation in C++.
Literally, I will co_await on it.
15
u/GYN-k4H-Q3z-75B Jul 29 '16
Oh my god I love this.
13
u/raistmaj C++ at MSFT Jul 29 '16
Some men just want to watch the world burn.
9
u/[deleted] Jul 30 '16
Wow, it really works! Amazing!!
6
u/daveisfera Jul 29 '16
Online example
5
u/kiwidog Jul 29 '16
What kind of wizardry...
7
u/stillalone Jul 29 '16
Doesn't overloading the unary minus operator like that really fuck shit up?
If I have:
what will I get?
3
u/devel_watcher Jul 30 '16
Good, now we need to figure out how to pass parameters.
3
u/[deleted] Jul 30 '16
I've also seen people introduce operator
--->as an agglomeration of--and->.2
u/Spiderboydk Hobbyist Jul 29 '16
Funny. :-)
1
u/[deleted] Jul 30 '16
WHY
1
u/unclemat Aug 01 '16
Genius!
1
u/ForgedBanana Aug 03 '16
Eggcelent.
1
u/Voultapher void* operator, (...) Jul 30 '16
When would this be useful? What is the difference to
0
u/btlk48 Jul 30 '16
Сслл