--- Bernie Bright <[EMAIL PROTECTED]> wrote:
> On Mon, 7 Oct 2002 08:09:32 -0400
> "Norman Vine" <[EMAIL PROTECTED]> wrote:
> 
> > ace project writes:
> > 
> >  > >
> > >
>
vector_of_elements.erase(&vector_of_elements[index]);
> > > > 
> > > > I think your are making the too rapid
> assumption that
> > > > an iterator is a pointer to an element.
> > > > 
> > > Thats the one I ment Fred (my mistake). It works
> for
> > > me (while I don't know whether is *really*
> correct).
> > 
> > FWIW - I think the intended method of the
> 'standard' writers is
> > 
> > vector.erase( vector.at( index ) );
> > 
> > but not all C++ implementations have the
> 'conforming' at() method.
> > 
> > AFA IK  - at() is in Microsoft V6 and V7 and
> g++3.X
> > 
> > Note a conforming vector<T>. at(index) method 
> > performs a range check on 'index'
> 
> and throws a std::out_of_range exception if index is
> out of range.
> 
> Has anyone suggested
> 
> vector.erase( vector.begin() + index )
This looks dangerous, I not sure whether vector
implements a operator+ function (mine does NOT). So in
mine case I would try to erase a element with address
vector.begin()+index, which would not do anything
except maybe throw a nasty segfault, since the chances
that a element exists with that address is slim.
> 
> yet?
> 
> Bernie
> 
> _______________________________________________
> Flightgear-devel mailing list
> [EMAIL PROTECTED]
>
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


Just use this code, it guaranteed valid until
something   invokes vector.resize() (implicit or
explicit)
vector_of_elements.erase(&vector_of_elements[index]);
//range NOT checked
or
vector_of_elements.erase(&vector_of_elements.at(index));
//range CHECKED

I think it works(dont sue me if I'm wrong) because
vector_of_elements[index] returns a reference to a
element, which can be transformed to a pointer for use
by erase(). The [] subscripting operator used here is
NOT the same as used by a basic array, thus not just a
"pointer to sizeof(elements)*index)" but a overwritten
operator (user implemented).


My opinion on the use/not use of STL is simple. USE
IT!   The people who made it probably have more
skill/experience in programming that the most of us
here (no flame intended) and we know it has been
stable in production enviroments for more then 10
years. 
I always use STL-libs if they are useful above any
other lib in single threaded(!) application. Threads
are a different case since threading is more dangerous
and the STL in not optimized for it.

Why invent the wheel twice ?

[rant/OT, plz do not argue about it, it is only my
opinion, nothing more]
I just *hate* the people who felt it needed to force
people on using ANSIstring, Cstring, String (and maybe
others that I don't know yet). C++ standard includes
"string", use it or loose it.
[/rant]

Leon

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com

_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to