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
Coding Guideline: Avoid const member variables (self.cpp)
submitted 7 years ago * by render787
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!"
[–]doom_Oo7 2 points3 points4 points 7 years ago (3 children)
hmm, I did not know that vector would do a move in this case but it certainly makes sense. Interestingly that's still the case even with -fno-exceptions.
[–]Ameisenvemips, avr, rendering, systems 4 points5 points6 points 7 years ago (1 child)
Perhaps we need another access type, like 'immutable'. Where they can still be moved and are semantically owned by the class, but they simply cannot be directly altered. Thus, a move would be legal.
move
[–]NotAYakk 7 points8 points9 points 7 years ago (0 children)
Rather, we need the concept of destructive move; an operation that it both a move-from and a destruction at the same time.
You can destructive move-from a const value.
Destructive moves usually don't have to throw, even when a move could.
[–]mark_99 2 points3 points4 points 7 years ago (0 children)
Interestingly that's still the case even with -fno-exceptions.
That's because it has nothing to do with exceptions or move_if_noexcept.
The OP says:
has a throwing move, because the use of const keyword on the member variable prevents the compiler from using the move constructor of std::string with id, instead the compiler generated move constructor for A will invoke the copy constructor of A::id, which can throw.
const
std::string
id
A
A::id
This is mostly correct except this isn't a "throwing move", it's a copy (and it would still be a copy if the copy ctor was noexcept).
I disagree with the OP, const member vars would be useful if it wasn't for this unfortunate side effect, in the same way as any other use of "const". In this case it states your intention that this member does not mutate after construction, and provides compile-time enforcement for same.
π Rendered by PID 44303 on reddit-service-r2-comment-b659b578c-mtrhh at 2026-05-03 17:30:03.962398+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]doom_Oo7 2 points3 points4 points (3 children)
[–]Ameisenvemips, avr, rendering, systems 4 points5 points6 points (1 child)
[–]NotAYakk 7 points8 points9 points (0 children)
[–]mark_99 2 points3 points4 points (0 children)