77cd227ec3
2001-09-25 Phil Edwards <pme@gcc.gnu.org> * docs/html/20_util/howto.html: Add anchor name. * docs/html/23_containers/howto.html: Line wrapping, another link. * docs/html/25_algorithms/howto.html: Another note. * docs/html/ext/howto.html: Link to SGI extensions. List DRs and link to them... * docs/html/ext/lwg-active.html: ...in this new file (from R19), * docs/html/ext/lwg-defects.html: and this new file (from R19). * docs/html/ext/sgiexts.html: New file. Mention SGI extensions carried over to libstdc++-v3. * docs/html/faq/index.html: Link to SGI extensions. Mention the "missing .." pseudobug. * docs/html/faq/index.txt: Regenerate. * include/bits/ios_base.h: DR-related comment cleanup. * include/bits/istream.tcc: Likewise. * include/bits/locale_facets.h: Likewise. * include/bits/locale_facets.tcc: Likewise. * include/bits/ostream.tcc: Likewise. * include/bits/std_bitset.h: Likewise. * include/bits/std_iosfwd.h: Likewise. * include/bits/std_istream.h: Likewise. * include/bits/std_ostream.h: Likewise. * include/bits/std_streambuf.h: Likewise. * include/bits/stl_pair.h: Likewise. * include/bits/streambuf_iterator.h: Likewise. * include/bits/std_map.h: Remove unused header inclusion guard _CPP_BITS_STL_TREE_H from around bits/stl_tree.h. * include/bits/std_set.h: Likewise. * include/bits/stl_function.h: Doxygen markup. * docs/doxygen/doxygroups.cc: New file, specifying module grouping. * libsupc++/typeinfo: Doxygen markup tweak. From-SVN: r45816
106 lines
4.2 KiB
HTML
106 lines
4.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
|
<html>
|
|
<head>
|
|
<meta HcodeP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
|
<meta NAME="AUTHOR" CONTENT="pme@gcc.gnu.org (Phil Edwards)">
|
|
<meta NAME="KEYWORDS" CONTENT="HOWTO, libstdc++, GCC, g++, libg++, STL">
|
|
<meta NAME="DESCRIPTION" CONTENT="HOWTO for the libstdc++ chapter 25.">
|
|
<meta NAME="GENERATOR" CONTENT="vi and eight fingers">
|
|
<title>libstdc++-v3 HOWTO: Chapter 25</title>
|
|
<link REL=StyleSheet HREF="../lib3styles.css">
|
|
<!-- $Id: howto.html,v 1.5 2001/09/17 23:24:39 pme Exp $ -->
|
|
</head>
|
|
<body>
|
|
|
|
<h1 CLASS="centered"><a name="top">Chapter 25: Algorithms</a></h1>
|
|
|
|
<p>Chapter 25 deals with the generalized subroutines for automatically
|
|
transforming lemmings into gold.
|
|
</p>
|
|
|
|
|
|
<!-- ####################################################### -->
|
|
<hr>
|
|
<h1>Contents</h1>
|
|
<ul>
|
|
<li><a href="#1">Prerequisites</a>
|
|
<li><a href="#2">Special <code>swap</code>s</a>
|
|
</ul>
|
|
|
|
<hr>
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
<h2><a name="1">Prerequisites</a></h2>
|
|
<p>The neatest accomplishment of the algorithms chapter is that all the
|
|
work is done via iterators, not containers directly. This means two
|
|
important things:
|
|
<ol>
|
|
<li>Anything that behaves like an iterator can be used in one of
|
|
these algorithms. Raw pointers make great candidates, thus
|
|
built-in arrays are fine containers, as well as your own iterators.
|
|
<li>The algorithms do not (and cannot) affect the container as a
|
|
whole; only the things between the two iterator endpoints. If
|
|
you pass a range of iterators only enclosing the middle third of
|
|
a container, then anything outside that range is inviolate.
|
|
</ol>
|
|
</p>
|
|
<p>Even strings can be fed through the algorithms here, although the
|
|
string class has specialized versions of many of these functions (for
|
|
example, <code>string::find()</code>). Most of the examples on this
|
|
page will use simple arrays of integers as a playground for
|
|
algorithms, just to keep things simple.
|
|
<a name="Nsize">The use of <B>N</B></a> as a size in the examples is
|
|
to keep things easy to read but probably won't be legal code. You can
|
|
use wrappers such as those described in the
|
|
<a href="../23_containers/howto.html">containers chapter</a> to keep
|
|
real code readable.
|
|
</p>
|
|
<p>The single thing that trips people up the most is the definition of
|
|
<em>range</em> used with iterators; the famous
|
|
"past-the-end" rule that everybody loves to hate. The
|
|
<a href="../24_iterators/howto.html#2">iterators chapter</a> of this
|
|
document has a complete explanation of this simple rule that seems to
|
|
cause so much confusion. Once you get <em>range</em> into your head
|
|
(it's not that hard, honest!), then the algorithms are a cakewalk.
|
|
</p>
|
|
<p>
|
|
</p>
|
|
<p>Return <a href="#top">to top of page</a> or
|
|
<a href="../faq/index.html">to the FAQ</a>.
|
|
</p>
|
|
|
|
<hr>
|
|
<h2><a name="2">Special <code>swap</code>s</a></h2>
|
|
<p>If you call <code> std::swap(x,y); </code> where x and y are standard
|
|
containers, then the call will automatically be replaced by a call to
|
|
<code> x.swap(y); </code> instead.
|
|
</p>
|
|
<p>This allows member functions of each container class to take over, and
|
|
containers' swap functions should have O(1) complexity according to
|
|
the standard. (And while "should" allows implementations to
|
|
behave otherwise and remain compliant, this implementation does in
|
|
fact use constant-time swaps.) This should not be surprising, since
|
|
for two containers of the same type to swap contents, only some
|
|
internal pointers to storage need to be exchanged.
|
|
</p>
|
|
<p>Return <a href="#top">to top of page</a> or
|
|
<a href="../faq/index.html">to the FAQ</a>.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
<hr>
|
|
<P CLASS="fineprint"><em>
|
|
Comments and suggestions are welcome, and may be sent to
|
|
<a href="mailto:libstdc++@gcc.gnu.org">the mailing list</a>.
|
|
<br> $Id: howto.html,v 1.5 2001/09/17 23:24:39 pme Exp $
|
|
</em></p>
|
|
|
|
|
|
</body>
|
|
</html>
|