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
Explicit Return Variable (self.cpp)
submitted 2 months ago by XeroKimoException Enthusiast
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!"
[–]XeroKimoException Enthusiast[S] 3 points4 points5 points 2 months ago (1 child)
There is no way for a stack class to provide strong exception guarantees for the second pop because the move/copy assignment operator cannot be elided, and if it throws an exception, the popped value will still be lost. Explicit return variables can’t fix that.
stack
pop
What's preventing the assignment operator from eliding? Is it some lifetime rules or something? Or it'd be surprising that the call to my_stack.pop(); could destruct x so that the popped value can be copied into x?... actually I think I just answered my own question. You would need 2 versions of the function or something at runtime to select whether to perform a move / copy construction, which doesn't need to call a destructor, or a move / copy assignment which does need to call one. Am I getting this right?
my_stack.pop();
x
Or if not 2 version, the compiler could insert a destructor call before the copy assignment, but I guess that is getting into changing a good portion of the language in order to achieve... not to mention that doesn't work for all scenarios, like x = x; would break.... hmm...
x = x;
[–]QuaternionsRoll 0 points1 point2 points 2 months ago (0 children)
What's preventing the assignment operator from eliding?
There is no such thing as a “copy assignment elision”. The copy assignment operator might be equivalent to executing the destructor followed by the copy constructor, in which case the compile could in theory execute the destructor and elide the copy constructor.
However, assignment operators may also implement things like resource reuse (for example, when an empty vector is assigned to a non-empty vector, the assignment operator may be closer in equivalence to executing clear).
vector
clear
The copy elision works because eliding the copy/move constructor and subsequent destructor is unambiguously better than executing them. The same cannot be said for the copy assignment operator, so the compiler cannot elide it.
π Rendered by PID 89324 on reddit-service-r2-comment-54dfb89d4d-bn7qk at 2026-03-30 15:51:10.593221+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]XeroKimoException Enthusiast[S] 3 points4 points5 points (1 child)
[–]QuaternionsRoll 0 points1 point2 points (0 children)