C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Q] order/offset of vector-elements persistent over operatio

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
dmoos AT esigma-systems D
Guest





PostPosted: Fri Feb 20, 2004 4:24 pm    Post subject: [Q] order/offset of vector-elements persistent over operatio Reply with quote



Hi,

is it guaranteed that the order and offset of vector-elements
does not change when doing a push_back() ?

When erasing a vector-element, is it guaranteed, that the order
and offset of the elements up to the one erased does not change ?

Is it guaranteed, that the order and offset of vector-elements
is the same in the destination when assigning vectors ?

Any help, hints, pointers are highly appreciated.

Thanks in advance for all your help.

Darius.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
James Kuyper
Guest





PostPosted: Mon Feb 23, 2004 2:13 am    Post subject: Re: [Q] order/offset of vector-elements persistent over oper Reply with quote



[email]pfffffrrrrt (AT) gmx (DOT) de[/email] (dmoos AT esigma-systems DOT de) wrote in message news:<c1537n$1dik0i$1 (AT) ID-193014 (DOT) news.uni-berlin.de>...
Quote:
Hi,

is it guaranteed that the order and offset of vector-elements
does not change when doing a push_back() ?

When erasing a vector-element, is it guaranteed, that the order
and offset of the elements up to the one erased does not change ?

Is it guaranteed, that the order and offset of vector-elements
is the same in the destination when assigning vectors ?

vector<> is a sequence container. For sequences, a.push_back(t) is
defined as equivalent to a.insert(a.end(),t). The fact that a.insert()
is supposed to leave the other elements of the sequence in the same
relative order is not explicitly stated anywhere, as far as I can see,
but it seems to be implied by the name "sequence", and implicitly
assumed in many places.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Michiel Salters
Guest





PostPosted: Mon Mar 01, 2004 5:05 pm    Post subject: Re: [Q] order/offset of vector-elements persistent over oper Reply with quote



[email]pfffffrrrrt (AT) gmx (DOT) de[/email] (dmoos AT esigma-systems DOT de) wrote in message news:<c1537n$1dik0i$1 (AT) ID-193014 (DOT) news.uni-berlin.de>...
Quote:
Hi,

is it guaranteed that the order and offset of vector-elements
does not change when doing a push_back() ?

When erasing a vector-element, is it guaranteed, that the order
and offset of the elements up to the one erased does not change ?

Is it guaranteed, that the order and offset of vector-elements
is the same in the destination when assigning vectors ?

Any help, hints, pointers are highly appreciated.

Thanks in advance for all your help.

Darius.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Yes, a Defect Report has clarified the situation. The offset
&v[n]-&v[0] must always be n, for any valid v[n] - just like
an array. Apparently everybody just "knew" this and nobody
noticed that the standard technically didn't require this,
until it was published.

Regards,
--
Michiel Salters

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Darius Moos
Guest





PostPosted: Tue Mar 02, 2004 4:34 pm    Post subject: Re: [Q] order/offset of vector-elements persistent over oper Reply with quote

On Mon, 01 Mar 2004 18:05:37 +0100, Michiel Salters wrote:
Quote:
pfffffrrrrt (AT) gmx (DOT) de (dmoos AT esigma-systems DOT de) wrote in message
news:<c1537n$1dik0i$1 (AT) ID-193014 (DOT) news.uni-berlin.de>...
is it guaranteed that the order and offset of vector-elements does not
change when doing a push_back() ?
When erasing a vector-element, is it guaranteed, that the order and
offset of the elements up to the one erased does not change ?
Is it guaranteed, that the order and offset of vector-elements is the
same in the destination when assigning vectors ?

Yes, a Defect Report has clarified the situation. The offset &v[n]-&v[0]
must always be n, for any valid v[n] - just like an array. Apparently
everybody just "knew" this and nobody noticed that the standard
technically didn't require this, until it was published.

Do you have a link/pointer to the mentioned defect report ?

Thanks in advance,

Darius.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
James Kuyper
Guest





PostPosted: Tue Mar 02, 2004 11:33 pm    Post subject: Re: [Q] order/offset of vector-elements persistent over oper Reply with quote

[email]Michiel.Salters (AT) cmg (DOT) nl[/email] (Michiel Salters) wrote in message news:<cefd6cde.0403010848.233003cf (AT) posting (DOT) google.com>...
Quote:
pfffffrrrrt (AT) gmx (DOT) de (dmoos AT esigma-systems DOT de) wrote in message news:<c1537n$1dik0i$1 (AT) ID-193014 (DOT) news.uni-berlin.de>...

I think that you referred to an important issue, but not the one
raised by the OP. I'll illustrate what I think he's talking about with
test code.

Quote:
Hi,

is it guaranteed that the order and offset of vector-elements
does not change when doing a push_back() ?

#include <vector>
#include <algorith>

// a is a std::vector<T>, non-empty.
T *backup = new T[a.size()];
std::copy(a.start(),a.end(),backup);
a.push_back(t);
if(std::equal(a.start(),a.end()-1,backup)
;// not explicitly guaranteed

Quote:
When erasing a vector-element, is it guaranteed, that the order
and offset of the elements up to the one erased does not change ?

// i is an iterator into 'a', which does NOT point at a[0]
std::vector<T>::iterator last_safe = i-1;
a.erase(i);
if(std::equal(a.start(), last_safe, backup))
; // not explicity guaranteed

Quote:
Is it guaranteed, that the order and offset of vector-elements
is the same in the destination when assigning vectors ?

// r refers to another std::vector<T>
r = a;
if(u==a)
; // This one is explicitly guaranteed as a post-condition
// on r=a

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Bart van Ingen Schenau
Guest





PostPosted: Thu Mar 04, 2004 5:39 pm    Post subject: Re: [Q] order/offset of vector-elements persistent over oper Reply with quote

On Tue, 2 Mar 2004 23:33:55 +0000 (UTC), [email]kuyper (AT) wizard (DOT) net[/email] (James
Kuyper) wrote:

Quote:
Michiel.Salters (AT) cmg (DOT) nl (Michiel Salters) wrote in message news:<cefd6cde.0403010848.233003cf (AT) posting (DOT) google.com>...
[email]pfffffrrrrt (AT) gmx (DOT) de[/email] (dmoos AT esigma-systems DOT de) wrote in message news:<c1537n$1dik0i$1 (AT) ID-193014 (DOT) news.uni-berlin.de>...

I think that you referred to an important issue, but not the one
raised by the OP. I'll illustrate what I think he's talking about with
test code.

Hi,

is it guaranteed that the order and offset of vector-elements
does not change when doing a push_back() ?

#include <vector
#include
// a is a std::vector T *backup = new T[a.size()];
std::copy(a.start(),a.end(),backup);
a.push_back(t);
if(std::equal(a.start(),a.end()-1,backup)
;// not explicitly guaranteed

if a.size() < a.capacity(), the guarantee does exist.
This follows from the requirement that the iterators and references to
elements in the vector are not invalidated.
Unless the implementation is capable of updating all possible
references and iterators, including those that are temporarily stored
elsewhere, the location of elements of the vector can not be changed.

Bart v Ingen Schenau

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
James Kuyper
Guest





PostPosted: Sun Mar 07, 2004 6:04 pm    Post subject: Re: [Q] order/offset of vector-elements persistent over oper Reply with quote

[email]Bart.van.Ingen.Schenau (AT) ict (DOT) nl[/email] (Bart van Ingen Schenau) wrote in message news:<7sgb40dsfskmtcheqndct5pbdpjfkcsipa (AT) 4ax (DOT) com>...
Quote:
On Tue, 2 Mar 2004 23:33:55 +0000 (UTC), [email]kuyper (AT) wizard (DOT) net[/email] (James
Kuyper) wrote:

[email]Michiel.Salters (AT) cmg (DOT) nl[/email] (Michiel Salters) wrote in message news:<cefd6cde.0403010848.233003cf (AT) posting (DOT) google.com>...
[email]pfffffrrrrt (AT) gmx (DOT) de[/email] (dmoos AT esigma-systems DOT de) wrote in message news:<c1537n$1dik0i$1 (AT) ID-193014 (DOT) news.uni-berlin.de>...

I think that you referred to an important issue, but not the one
raised by the OP. I'll illustrate what I think he's talking about with
test code.

Hi,

is it guaranteed that the order and offset of vector-elements
does not change when doing a push_back() ?

#include <vector
#include
// a is a std::vector T *backup = new T[a.size()];
std::copy(a.start(),a.end(),backup);
a.push_back(t);
if(std::equal(a.start(),a.end()-1,backup)
;// not explicitly guaranteed

if a.size() < a.capacity(), the guarantee does exist.
This follows from the requirement that the iterators and references to
elements in the vector are not invalidated.
Unless the implementation is capable of updating all possible
references and iterators, including those that are temporarily stored
elsewhere, the location of elements of the vector can not be changed.

Just because two iterators remain valid, doesn't guarantee that the
locations those iterators refer to remain in the same order. Changing
the order doesn't require changing the iterators: the information
needed to figure out where the next item may be found could be stored
in the container itself, or in a wrapper around each of the contained
objects.

You might be able to derive a conclusion that it's impossible to have
the order be changeable while satisfying the complexity requirements
on std::vector and std::vector::iterator. However, that's a very
indirect argument. My point was that the guarantee, while it may be
derivable from the standard, is not given explicitly in the standard.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.