Because you cannot call at in a const vector object.
If you had a non- const version, the following:
const std::vector<int> x(10); x.at(0);
will not compile. Having a const version makes this possible and, at the same time, prevents you from actually changing what at returns - this is a contract, since the vector is const .
The non const version can be called not by the const object and allows you to change the returned element, which is also valid because the vector is not const.
const std::vector<int> x(10); std::vector<int> y(10); int z = x.at(0);
source share