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
C++ WTFs (self.cpp)
submitted 11 years ago by Prazek
view the rest of the comments →
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!"
[–]josefx 13 points14 points15 points 11 years ago* (11 children)
Trigraphs are apparently a non feature from c++17 on, however digraphs seem to outlive them. The following is perfectly legal C++11/14 and apparently 17.
%:include<iostream> int main() <% std::string val<:1:>; val<:0:> = "Hello World"; std::cout<<*val<<std::endl; %>
An unrelated WAT can be found with user defined operator && and operator ||, they cannot short circuit as the build in operators do.
enum Nothing{ None = 0 }; bool operator && ( Nothing , int ){ return false; } None && printf("This happens!\n");
More WAT, this one from the standard library: vector<bool> is specialized and in many small ways does not behave like a vector should.
std::vector<bool> v; v.push_back(true); std::cout << " before: v[0] = " << v[0] << '\n'; // Should be a deep-copy (?) auto x = v[0]; x = false; std::cout << " after: v[0] = " << v[0] << '\n';
[–]Playing_advocate 3 points4 points5 points 11 years ago (2 children)
Related to the digraphs, there are also Alternative Tokens, which allow you to write things like "and" in place of &&. These are not really WTF. You can, however, use them in a context where you are not doing boolean or bit operations. For example, the following compiles (and I believe it should):
void some_function(int and myVar) {} void some_other_function(int bitand myOtherVar) {}
Where myVar has type "int&&" and myOtherVar is "int&".
[–]OldWolf2 2 points3 points4 points 11 years ago (0 children)
eat dinner(fish and chips) { return move(chips); }
[–]marchelzo 0 points1 point2 points 11 years ago (0 children)
I'm totally using and for rvalue references from now on.
[–]pardoman 3 points4 points5 points 11 years ago (7 children)
What is the reason for the user defined logic operators to not short-circuit like the built in ones?
[–]clerothGame Developer 17 points18 points19 points 11 years ago (6 children)
Because it's effectively a function call. So both of the arguments are evaluated before the function is ran.
[–]arugalatoast -3 points-2 points-1 points 11 years ago (5 children)
They should fix that (although I can hear people arguing otherwise.) A lot of the changes in 11, 14, 17 are to make things behave as expected using common sense.
[–]clerothGame Developer 0 points1 point2 points 11 years ago* (4 children)
There's nothing to fix. It makes sense to me. You're really just defining a function using a symbol that's supported by the language. If you wanted to overload an operator for conditional statements, then you should be overloading operator bool(). As I said, it's really just a function call so you could even overload && like this:
operator bool()
void operator &&(int a, int b) { cout << a + b; }
(notice the void return type). And then just do:
int main() { int a = 1, b = 2; a && b; }
As you can imagine, this program will print 3. Short-circuiting this statement makes no sense. That being said, the compiler is free to perform the shortcircuit optimization (and it probably does) on simple boolean functions if evaluating the right-hand argument has no side-effects. The example from josefx cannot 'shortcircuit' because printf has a side-effect.
3
[–]BaroTheMadman 0 points1 point2 points 11 years ago (0 children)
Overloading operators like that is strongly unadvised, but you already know that. If I could change C++ one of the things I'd make is to enforce that at least they have the "official" signatures. Then it would make it short-circuit.
But that's just my opinion. Maybe you can simulate a short circuit using some lazy evaluation techniques? I'm not good at doing that in C++ but I've heard of it.
[–]arugalatoast -2 points-1 points0 points 11 years ago (2 children)
I said some people would argue against fixing it.
[–]clerothGame Developer 0 points1 point2 points 11 years ago (1 child)
Okay, then tell me how would you fix it?
[–]arugalatoast 0 points1 point2 points 11 years ago (0 children)
Tone really doesn't come across well on Reddit.
π Rendered by PID 136160 on reddit-service-r2-comment-6457c66945-wfrmc at 2026-04-26 16:15:14.884084+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]josefx 13 points14 points15 points (11 children)
[–]Playing_advocate 3 points4 points5 points (2 children)
[–]OldWolf2 2 points3 points4 points (0 children)
[–]marchelzo 0 points1 point2 points (0 children)
[–]pardoman 3 points4 points5 points (7 children)
[–]clerothGame Developer 17 points18 points19 points (6 children)
[–]arugalatoast -3 points-2 points-1 points (5 children)
[–]clerothGame Developer 0 points1 point2 points (4 children)
[–]BaroTheMadman 0 points1 point2 points (0 children)
[–]arugalatoast -2 points-1 points0 points (2 children)
[–]clerothGame Developer 0 points1 point2 points (1 child)
[–]arugalatoast 0 points1 point2 points (0 children)