Consider the two following snippets:
bool foo(const int &lhs, const int &rhs)
{
const std::map<int, int> bar{{1, 2}, {2, 1}, {3, 3}};
return bar.at(lhs) < bar.at(rhs);
}
and:
bool foo(const int &lhs, const int &rhs)
{
std::map<int, int> bar{{1, 2}, {2, 1}, {3, 3}};
return bar[lhs] < bar[rhs];
}
My questions:
- In the first snippet, is there a faster
const
function thanat()
that will not preform bound-checking? - Which is better (faster, more idiomatic), for calling once and many times?