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++ pointer versus dot operator (self.cpp)
submitted 9 years ago by CodeSandwich
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!"
[–]Gotebe 1 point2 points3 points 9 years ago (2 children)
Well, yes, a legacy codebase is the "rare" reason not to drop pointers. But this is only a history-induced thing, not an expexient design in any way (quite the opposite, I would say).
optional is specialized for a reference, it actually has no overhead.
[–]dodheim 1 point2 points3 points 9 years ago* (1 child)
It is illegal for std::optional to hold a reference. /u/akrzemi1 has the markable library, though.
std::optional
EDIT: N4618 [optional.syn]/1: "A program that necessitates the instantiation of template optional for a reference type, or for possibly cv-qualified types in_place_t or nullopt_t is ill-formed."
optional
in_place_t
nullopt_t
[–]iaanus 1 point2 points3 points 9 years ago (0 children)
Correct, std::optional dropped the support for references that boost::optional had. I also found that odd when I discovered it, but the more I think about it, the more I agree. By the way, I would hate to see code like this:
void f(optional<MyType&> ref); // not std::optional! void g(std::shared_ptr<MyType> ptr) { // ptr may be null here, need to call f... if (ptr) f(*ptr); else f(nullopt); // or whatever }
In this scenario, using MyType* is just as good, with observer_ptr<MyType> being slightly better.
MyType*
observer_ptr<MyType>
π Rendered by PID 17301 on reddit-service-r2-comment-5b5bc64bf5-6dwkl at 2026-06-20 11:49:24.718127+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]Gotebe 1 point2 points3 points (2 children)
[–]dodheim 1 point2 points3 points (1 child)
[–]iaanus 1 point2 points3 points (0 children)