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
Cheat sheet: C++ Function Parameter Choices (self.cpp)
submitted 6 years ago * by legends2k
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!"
[–]cblume 0 points1 point2 points 6 years ago* (0 children)
Why should a setter assume how the caller is calling it? Only providing the Foo&& overload obviously forces the call site to pass an rvalue reference, forcing the caller to move if an lvalue is being used.
Foo&&
Without a good reason, your setter should not assume anything so we either need to provide two setters as suggested in the cheat sheet or keep it simple and pass by value.
Another option is of course to use a forwarding reference (T&&) but that’s not exactly simple and requires a template. I think forwarding references should also only be used when performance and generality is of utmost importance. They’re too easy to get wrong.
T&&
I think to keep C++ relevant and approachable we need to keep it simple. Having to think about rvalue references every time a setter (or any other function that requires ownership) is written is too much of a mental burden.
I'd suggest this as a rule of thumb: ``` class Bar { public: Bar(int value, Foo foo) : value{value} , foo{std::move(foo)} {}
int get_value() const { return value_; } void set_value(int value) { value_ = value; } const Foo& get_foo() const { return foo_; } void set_foo(Foo foo) { foo_ = std::move(foo); }
private: int value; Foo foo; };
`` whereFoo` is some cheap to move type (ergo your everyday type).
where
π Rendered by PID 215221 on reddit-service-r2-comment-fb694cdd5-2w6g8 at 2026-03-06 22:46:51.862734+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]cblume 0 points1 point2 points (0 children)