3 ms·
std::optional<std::reference_wrapper<T>> is how we deal with this [lovely isn't it?].
by psyclobe 5y ago
std::optional<std::reference_wrapper<T>> is how we deal with this [lovely isn't it?].
- twic 5y agoIndeed. The author writes: > Whenever the idea of an optional reference comes up, inevitably somebody will bring up the point that we don’t need to support optional<T&> because we already have in the language a perfectly good optional reference: T*. But i have never heard this said even once. Rather, inevitably someone will bring up the point that you can do it with reference_wrapper. Check it out: https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper#Example https://en.cppreference.com/w/cpp/utility/functional/referen...