I looked several online std::optional documentary over the internet. However I could not be able to find any direct comparison between two cases below:
case 1:
SomePointer* foo::get_some_pointer(cont int value) {
auto result = myMap.find(value);
if (result != myMap.end()) {
return const_cast<SomePointer*>(&result->second);
}
return nullptr;
}
case 2
std::optional<SomePointer*> foo::get_some_pointer (cont int value) {
auto result = myMap.find(value);
if (result != myMap.end()) {
return std::optional<SomePointer*>{&result->second};
}
return std::nullopt;
}
What are the advantages/disadvantages of the case 1 over the case 2(nullopt over nullptr) ?