[Please do not mail me a copy of your followup]
Doug Mika <
doug...@gmail.com> spake the secret code
<
d10e9a51-e713-4eea...@googlegroups.com> thusly:
>I found the following improvement of our vector class in my book.
It's not an improvement. std::vector<> already has range-checked
access through the use of the at() member function.
All this is doing is making operator[] a synonym for at(), forcing all
accesses to be range-checked.
This is actually a step backwards.
C++'s std::vector<> has a non-range checked accessor and a
range-checked accessor because C++ follows the philosophy of "don't pay
for what you don't use". If you don't need range-checked accessing,
then you shouldn't have to pay the cost of range checking every access
and you use operator[]. If you want range-checked accessing, then you
can decide to pay the cost and use at().
Making operator[] do range-checking is simply going to confuse *any*
reader of your code because they are culturally trained that
at is for range checking and operator[] is for unchecked access.
>template<typename T> class Vec : public std::vector<T> {
>public:
> using vector<T>::vector;
This is a "using declaration"
<
http://en.cppreference.com/w/cpp/language/using_declaration>
--
"The Direct3D Graphics Pipeline" free book <
http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <
http://computergraphicsmuseum.org>
The Terminals Wiki <
http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <
http://legalizeadulthood.wordpress.com>