Why having const and non-const accessors?
Why do the STL containers define const and non-const versions of accessors ? What is the advantage of defining const T& at(unsigned int i) const and T& at(unsigned int) and not only the non-const version ? Because you wouldn't be able to call at on a const vector object. If you only had the non- const version, the following: const std::vector<int> x(10); x.at(0); would not compile. Having the const version makes this possible, and at the same time prevents you from actually changing what at returns - which is by contract, since the vector is const . The non- const version can be called on a