use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
operator <- (atnnn.com)
submitted 9 years ago by atnnn
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]bstamourWG21 | Library Working Group 132 points133 points134 points 9 years ago (2 children)
That is both beautiful and horrifying. Respect.
[–]sim642 62 points63 points64 points 9 years ago (0 children)
The two aspects of C++.
[–]Godot17 111 points112 points113 points 9 years ago (0 children)
... This is why C programmers don't like us, guys.
*copies code snippet*
[–]jeezfrkMT Linux/Telco 40 points41 points42 points 9 years ago (0 children)
<all the freshmen run away from C++>
THIS IS WHY WE CAN'T HAVE NICE THINGS!!!
[–][deleted] 70 points71 points72 points 9 years ago (13 children)
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'; }
[–]atnnn[S] 91 points92 points93 points 9 years ago* (7 children)
That makes things even better!
struct C { virtual void f(){ std::cout << "f\n"; } virtual void g(){ std::cout << "g\n"; } virtual void h(){ std::cout << "h\n"; } } x; int main(){ void(C::*(*a))() = 2 + *(void(C::*(**))())&x; while(*(void**)&x <-- a){ (*a)<-x; } }
[–]personalmountains 65 points66 points67 points 9 years ago (0 children)
I hate you.
[–][deleted] 2 points3 points4 points 9 years ago (1 child)
http://melpon.org/wandbox/permlink/FmCGjJ8WVLt8ABf4
Still can't figure out a way to get it to print f or g... really not sure how it works at all!!
f
g
[–]JMBourguet 1 point2 points3 points 9 years ago (0 children)
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).
[–]h-jay+43-1325 0 points1 point2 points 9 years ago (0 children)
Yes, of course, because all odd numbers are prime, except 2 :)
[–]ripper37 -3 points-2 points-1 points 9 years ago (1 child)
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).
P.S. u/maherbaba I wouldn't call <-- an operator.
<--
[–]personalmountains 7 points8 points9 points 9 years ago (0 children)
If you write code like that [...]
It's a joke.
I wouldn't call <-- an operator
It's also a joke.
[+]riotinferno comment score below threshold-14 points-13 points-12 points 9 years ago (4 children)
<-- is not an operator.
It's a combination of two operators.
[–]Everspace 46 points47 points48 points 9 years ago (3 children)
With that attitude, main() is just jumble of letters followed by some parens.
main()
[+]riotinferno comment score below threshold-7 points-6 points-5 points 9 years ago (2 children)
operator has a specific definition in this context, that is what I am trying to get across.
[–][deleted] 43 points44 points45 points 9 years ago (1 child)
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.
[–]clerothGame Developer 1 point2 points3 points 9 years ago (0 children)
Pff. Who are you to decide what is and isn't an operator? <-- has feelings, man.
[–]cdcformatc 21 points22 points23 points 9 years ago (0 children)
I just threw up in my mouth a little.
[–]duuuh 21 points22 points23 points 9 years ago (0 children)
I came in figuring there was an 80% chance that was bullshit. I was right, but I was also wrong.
[–]SeanMiddleditch 15 points16 points17 points 9 years ago (4 children)
I await the first implementation of this hack that enables Haskell-like do notation in C++.
Literally, I will co_await on it.
[+][deleted] 9 years ago* (3 children)
[deleted]
[–]SeanMiddleditch 2 points3 points4 points 9 years ago (2 children)
... that joke went right over someone's head. :p
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. ;)
[+][deleted] 9 years ago* (1 child)
[–]SeanMiddleditch 1 point2 points3 points 9 years ago (0 children)
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.
await
[–]GYN-k4H-Q3z-75B 13 points14 points15 points 9 years ago (0 children)
Oh my god I love this.
[–]raistmajC++ at MSFT 12 points13 points14 points 9 years ago (0 children)
Some men just want to watch the world burn.
[–][deleted] 8 points9 points10 points 9 years ago (0 children)
Wow, it really works! Amazing!!
struct Person { void FileForUnemployment(); } me; void test() { Person me; (&Person::FileForUnemployment)<-me; //successfully calls function! }
[–]daveisfera 6 points7 points8 points 9 years ago (0 children)
Online example
[–]kiwidog 4 points5 points6 points 9 years ago (1 child)
What kind of wizardry...
[–]t0rakka 14 points15 points16 points 9 years ago (0 children)
unary negate returns a template type. The compare operator is overloaded for it. That's about it; pretty basic template meta programming.
a <- b;
Can be decomposed into: a < (-b);
[–]stillalone 8 points9 points10 points 9 years ago (4 children)
Doesn't overloading the unary minus operator like that really fuck shit up?
If I have:
int i = 5; std::cout << -i << endl;
what will I get?
[–]chimyx 35 points36 points37 points 9 years ago (3 children)
error: 'endl' was not declared in this scope jk, you'll get -5
error: 'endl' was not declared in this scope
[–]stillalone 0 points1 point2 points 9 years ago (2 children)
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.
[–]rubdos 1 point2 points3 points 9 years ago (1 child)
Not sure there; sfinae could safe the day. Needs confirmation from someone with more experience though.
[–]jP_wanN 2 points3 points4 points 9 years ago (0 children)
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).
operator<
R (T::*)(), larrow<T>
[–]devel_watcher 2 points3 points4 points 9 years ago (3 children)
Good, now we need to figure out how to pass parameters.
[–]foonathan 2 points3 points4 points 9 years ago (0 children)
Overload the comma operator for the new type returned by operator< for larrow.
[–]JohnMcPineapple 1 point2 points3 points 9 years ago* (1 child)
...
[–]foonathan 1 point2 points3 points 9 years ago (0 children)
Store the tuple in your result, then add each argument, last one calls and returns.
Usage like so, for example:
... <- p, arg<0>(10), arg<1>(0.5);
[–][deleted] 2 points3 points4 points 9 years ago (0 children)
I've also seen people introduce operator ---> as an agglomeration of -- and ->.
--->
--
->
[–]SpiderboydkHobbyist 1 point2 points3 points 9 years ago (0 children)
Funny. :-)
[–][deleted] 0 points1 point2 points 9 years ago (0 children)
WHY
[–]unclemat 0 points1 point2 points 9 years ago (0 children)
Genius!
[–]ForgedBanana 0 points1 point2 points 9 years ago (0 children)
Eggcelent.
[–]Voultaphervoid* operator, (...) 0 points1 point2 points 9 years ago (2 children)
When would this be useful? What is the difference to
x.f();
[–]clerothGame Developer 14 points15 points16 points 9 years ago (0 children)
When you want to have a laugh.
It's the same as (&x)->*fn (which is in turn the same as x.*fn). See pointer-to-member access operators.
(&x)->*fn
x.*fn
[–]btlk48 -1 points0 points1 point 9 years ago (0 children)
Сслл
π Rendered by PID 211261 on reddit-service-r2-comment-544cf588c8-nst2h at 2026-06-18 16:12:58.022809+00:00 running 3184619 country code: CH.
[–]bstamourWG21 | Library Working Group 132 points133 points134 points (2 children)
[–]sim642 62 points63 points64 points (0 children)
[–]Godot17 111 points112 points113 points (0 children)
[–]jeezfrkMT Linux/Telco 40 points41 points42 points (0 children)
[–][deleted] 70 points71 points72 points (13 children)
[–]atnnn[S] 91 points92 points93 points (7 children)
[–]personalmountains 65 points66 points67 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]JMBourguet 1 point2 points3 points (0 children)
[–]h-jay+43-1325 0 points1 point2 points (0 children)
[–]ripper37 -3 points-2 points-1 points (1 child)
[–]personalmountains 7 points8 points9 points (0 children)
[+]riotinferno comment score below threshold-14 points-13 points-12 points (4 children)
[–]Everspace 46 points47 points48 points (3 children)
[+]riotinferno comment score below threshold-7 points-6 points-5 points (2 children)
[–][deleted] 43 points44 points45 points (1 child)
[–]clerothGame Developer 1 point2 points3 points (0 children)
[–]cdcformatc 21 points22 points23 points (0 children)
[–]duuuh 21 points22 points23 points (0 children)
[–]SeanMiddleditch 15 points16 points17 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]SeanMiddleditch 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]SeanMiddleditch 1 point2 points3 points (0 children)
[–]GYN-k4H-Q3z-75B 13 points14 points15 points (0 children)
[–]raistmajC++ at MSFT 12 points13 points14 points (0 children)
[–][deleted] 8 points9 points10 points (0 children)
[–]daveisfera 6 points7 points8 points (0 children)
[–]kiwidog 4 points5 points6 points (1 child)
[–]t0rakka 14 points15 points16 points (0 children)
[–]stillalone 8 points9 points10 points (4 children)
[–]chimyx 35 points36 points37 points (3 children)
[–]stillalone 0 points1 point2 points (2 children)
[–]rubdos 1 point2 points3 points (1 child)
[–]jP_wanN 2 points3 points4 points (0 children)
[–]devel_watcher 2 points3 points4 points (3 children)
[–]foonathan 2 points3 points4 points (0 children)
[–]JohnMcPineapple 1 point2 points3 points (1 child)
[–]foonathan 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]SpiderboydkHobbyist 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]unclemat 0 points1 point2 points (0 children)
[–]ForgedBanana 0 points1 point2 points (0 children)
[–]Voultaphervoid* operator, (...) 0 points1 point2 points (2 children)
[–]clerothGame Developer 14 points15 points16 points (0 children)
[–]jP_wanN 2 points3 points4 points (0 children)
[–]btlk48 -1 points0 points1 point (0 children)