[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Missing class member in stl_vector?



On Thu, 10 Aug 2000, Christoph Baumann
(cbauman1@ix.urz.uni-heidelberg.de) wrote:

> I have the following problem. In a c++ program I use the vector
> template. Acording to "The C++ Programming Language" by Bjarne
> Stroustrup there should be a member at() for [range] checked
> random access to components of a vector. But it seems that there
> is only operator[] implemented in libstdc++. Is the member I
> need named differently or is there some sort of workaround?

Christoph

Perhaps you could write your own class that inherits publicly from
vector<T>, providing a public member function T& at(index_type) that
does the range check you require then uses operator[] for indexing.
Here, index_type is what ever type your STL vector uses for indices,
I'd think unsigned int. Please look.

I do not have the standard here to refer to, to tell you what at
exception the at member should throw. If you don't care about
recovery, you could just call abort() if a range error occurs.

You might go to PJ Plauger's Dinkumware site web and see if he has
an online copy of the 1996 draft standard (which is quite close to
the adopted ISO standard). He may have other information on what
at() should throw. (Sorry, I don't have Dinkumware's URL, you might
search the web for it.)

If you have access to a Borland or MS VC++ compiler, you could look
that version of the STL vector<>. That will give you some hints.

If I recall correctly, the STL in libstdc++ is from Silicon
Graphics.  Their website may shed some light.

The STL uses overloading on the keyword const to distinguish between
lvalue and rvalue use of members such as operator[]. Keep it simple
until and unless you find you need this distinction, then study the
STL with this in mind to figure out what to do.

Hope this helps

--David
David Teague, dbt@cs.wcu.edu
Debian GNU/Linux Because software support is free, timely,
                 useful, technically accurate, and friendly.
                 (I hope this is all of the above.)

> * "External Error : INTELLIGENCE not found !"                *




Reply to: