Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Again a simple question about std::vector

Reply
Thread Tools

Again a simple question about std::vector

 
 
Jerry Coffin
Guest
Posts: n/a
 
      04-06-2008
In article <98c82a92-ed6a-4cb9-916d-ca7132ba40e9
@s50g2000hsb.googlegroups.com>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...

[ Allocator instances ]

> If == must return true, then it doesn't mean anything. If an
> implementation doesn't use it, always assuming it returns true,
> then it doesn't mean anything.


Yes and no. A container implementation is free to assume that it returns
true, in which case you're right, at least for use with the standard
containers in that implementation, it's basically pointless.

OTOH, you can use non-equal allocators, as long as you don't care about
portability to implementations that don't support it. You can also
create your own container classes that support non-equal allocators,
even if the ones supplied by your standard library vendor don't.

OTOH, if your interest is exclusively in writing code that will work
with essentially any standard library implementation, then operator== is
pretty well pointless, because it's always going to return true.

[ ... ]

> > If it just means swapping their contents, I don't think the
> > possibility of non-constant time is an "or" -- I think it's
> > linear time AND you face the possibility of an exception (if
> > either allocator throws).

>
> Exactly. That's why I tend to favor the idea that swapping
> containers means swapping their allocators as well.


That certainly seems like what I'd do in any case.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      04-07-2008
In article <ft2qiv$d07$(E-Mail Removed)>, (E-Mail Removed) says...

[ ... ]

> > Contrary to the implication elsethread, there's no real difference
> > between std::swap<vector, vector> and vector::swap(vector). According to
> > section 23.2.4.4, the standard library is required to contain a
> > specialization of std::swap for vector so that if v1 and v2 both refer
> > to vectors, std:swap(v1, v2) is equivalent to v1.swap(v2).

>
> Right, I wasn't aware that it was actually a requirement. I guess that
> applies to every container, then (I can't think why it shouldn't).


I believe that's correct, yes.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Again??? AGAIN???? NYC XYZ Firefox 4 04-23-2006 12:23 PM
HttpSession gets generated again and again!! PLEASE HELP ME!!!! che Java 2 10-10-2005 10:20 PM
A simple question turns into badgering.....again Richard HTML 18 10-21-2003 06:27 AM
jserve booting again and again amit Java 0 10-02-2003 04:26 PM
IMPORTANT! Changes to your Cable Internet Service (again & again) Charlie Computer Support 4 07-17-2003 01:18 AM



Advertisments