🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Joe Buck Wed, 20 Mar 1996 00:26
"swap" and the HP STL implementation
#3742
Author: 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 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads