As the title says: Is there any guarantee from C++ Standard to be sure the left side of &&
(or and
) operator always evaluated first? To be honest, I couldn't search in C++17 Standard, I don't know which section I most look for.
Sample of Problem:
I want to do something like this:
std::unordered_map<std::size_t, std::weak_ptr<T>> objects;
bool f (std::size_t const id) {
bool result = false;
if (not objects.at(id).expired()) {
auto const& object = objects.at(id).lock();
/* Here left side of `and` most be evaluated first */
result = object->parent->remove(id) and
objects.erase(id) == 1;
}
return result;
}
And want to be sure there is no problem with the code.