optional
optional copied to clipboard
or_else of an Optional with a reference
All implementations of or_else
in the case of an optional with a reference return optional<T>
.
I ran into an issue with that, and when changing all signatures to optional<T&>
it was fixed.
Isn't returning an optional<T>
in these cases creating a copy of the contained reference?
Example:
struct IF
{
virtual void foo() = 0;
};
struct Impl : IF
{
void foo() override {}
};
Impl instance{};
tl::optional<IF&> test = tl::optional<IF&>{instance}.or_else([]() { std::cout << "bad"; });
Can anyone confirm that the example above does not work? What am I missing?