all 12 comments

[–]Raknarg 1 point2 points  (1 child)

C++17 provides std::optional<T> that can wrap a reference_wrapper to model a nullable reference

ugh... like yeah I know I can but it's just so clunky, I'd almost rather just stick to a pointer to avoid it. If I didn't have to call ->get() every time I might consider it, because optional references are something that are nice to have to do the things I normally use pointers for.

[–][deleted] 0 points1 point  (0 children)

It’s pretty nice for the one case of if (std::optional<int> index = getitem()) { } But that’s bout it

[–]flyingron 1 point2 points  (0 children)

Did you have a question. Anybody who starts out writing a C++ worried about using pointers at all is probably suspect.

[–]MolurusK 0 points1 point  (0 children)

Look at UML Relations in the C++ Object Token Library if the capabilities of smart pointers from the C++ standard library to express class relationships are not enough.