Is it safe to declare the following function noexcept
even though v.at(idx)
could theoretically throw a out_of_range
exception, but practically not due to the bounds check?
int get_value_or_default(const std::vector<int>& v, size_t idx) noexcept {
if (idx >= v.size()) {
return -1;
}
return v.at(idx);
}
Aucun commentaire:
Enregistrer un commentaire