🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3742

"swap" and the HP STL implementation

#3742
From: Joe Buck
Date: Wed, 20 Mar 1996 00:26
42 lines
2351 bytes
Many STL containers and standard library objects (e.g. string) provide a
swap function, since it is often much cheaper to exchange two complex
objects directly than to use a temporary.

STL also includes iter_swap, for swapping two objects given iterators
to point to them, and in the STL implementation the sort algorithm uses
iter_swap heavily.  But iter_swap doesn't use swap: this means that
things like sorts of vectors of strings are slow.  ObjectSpace copied
HP's implementation, so theirs has the same deficiency.

Is there any reason why iter_swap can't be implemented as

template <class ForwardIterator1, class ForwardIterator2>
inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b) {
    swap(*a, *b);
}

which would gain efficiency in cases where a fast swap exists or could
be provided?

Also (to be sure that this is standard-related) would it make sense to
either require, or strongly suggest as a quality-of-implementation
mechanism, that higher-level STL algorithms use lower-level algorithms in
a prescribed way so that if a user implements specializations for some
algorithms, he/she can be assured that the others run faster?





-- 
-- Joe Buck 	<jbuck@synopsys.com>	(not speaking for Synopsys, Inc)

Work for something because it is good,
not just because it stands a chance to succeed.	   -- Vaclav Havel
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <4inc97$e22@hermes.synopsys.com>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: jbuck@Synopsys.COM (Joe Buck)
Newsgroups: comp.std.c++
Subject: "swap" and the HP STL implementation
Date: 19 Mar 1996 16:26:07 PST
Organization: Synopsys Inc., Mountain View, CA 94043-4033
Approved: austern@isolde.mti.sgi.com
Message-ID: <4inc97$e22@hermes.synopsys.com>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 19 Mar 1996 22:25:43 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMU9Qxky4NqrwXLNJAQEuEAIAhelLRbh1KpC1jgSXRPDLCdtfz+eg3A7d
 mdutwexgRUvo+b9uVsNmhT1A8GbRznpvTVr9UTGKAwLRjejIs39Esw==
 =vf3x
Originator: austern@isolde.mti.sgi.com