3 ms·
Some monadic method would be nice but as you probably know, it’s trivial to implement one yourself. You can store a reference in optional using reference_wrapp
by CyberRabbi 6y ago
Some monadic method would be nice but as you probably know, it’s trivial to implement one yourself.
You can store a reference in optional using reference_wrapper https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper https://en.cppreference.com/w/cpp/utility/functional/referen...
- beached_whale 6y agoreference wrapper breaks in generic contexts.
- CyberRabbi 6y agoCould you provide an example?
- clappski 6y agoYou have to add special handling for the case that T == std::reference_wrapper<T> so you can call .get() on it to expose the underlying value. In the case of std::optional vs a pointer type (raw or smart) you can consistently use operator* to get to the underlying value. I think this is what was meant.
- beached_whale 6y agoalso if you are doing something like decltype( *val ) to get at the underlying type.