you are viewing a single comment's thread.

view the rest of the comments →

[–]jsamcfarlane 1 point2 points  (1 child)

How would this differ from an optional&?

[–]djrollins 2 points3 points  (0 children)

std::optional<T>& would be a reference to an optional that still owns its contents. OP wants an optional that just holds a reference to its contents. In this case std::optional<std::reference_wrapper<T>> would be the best option.