Things like the following happen all to often when using std::optional:
void bar(const Foo*);
void baz(const std::optional<Foo>& foo) {
// This is clunky to do every time.
bar(foo.has_value() ? &foo.value() : nullptr);
// Why can't I do this instead?
bar(foo.as_ptr());
}
This is the sort of thing that makes it annoying to adopt std::optional, because then it's extremely inconvenient to use it with existing code that expects pointers instead. So why isn't something like .as_ptr() provided with std::optional? It seems like a pretty obvious convenience function.