7fa94fbb93
2009-07-20 Benjamin Kosnik <bkoz@redhat.com> * doc/xml/manual/intro.xml: Escape '&', validate. * doc/xml/manual/using.xml: Validate, dead link check. * doc/xml/manual/strings.xml: Same. * doc/xml/manual/appendix_contributing.xml: Same. * doc/xml/manual/iterators.xml: Same. * doc/xml/manual/spine.xml: Same. * doc/xml/faq.xml: Remove redundant xreflabel entities. * doc/xml/gnu/gpl-3.0.xml: Same. * doc/xml/manual/mt_allocator.xml: Same. * doc/xml/manual/allocator.xml: Same. * doc/xml/manual/ctype.xml: Same. * doc/xml/manual/codecvt.xml: Same. * doc/xml/manual/backwards_compatibility.xml: Same. * doc/xml/manual/shared_ptr.xml: Same. * doc/xml/manual/abi.xml: Same. * doc/xml/manual/auto_ptr.xml: Same. * doc/xml/manual/internals.xml: Same. * doc/xml/manual/parallel_mode.xml: Same. * doc/xml/manual/bitmap_allocator.xml: Same. * doc/xml/manual/build_hacking.xml: Same. * doc/xml/manual/evolution.xml: Same. * doc/xml/manual/debug.xml: Same. * doc/xml/manual/localization.xml: Same. * doc/xml/manual/appendix_contributing.xml: Same. * doc/xml/manual/locale.xml: Same. * doc/xml/manual/messages.xml: Same. * doc/xml/manual/spine.xml: Same. * doc/xml/manual/test.xml: Same. * doc/xml/book.txml: Same. * doc/xml/spine.xml: Same. * doc/xml/api.xml: Clean up ulink targets, convert to link if possible. * doc/xml/manual/backwards_compatibility.xml: Same. * doc/xml/manual/concurrency.xml: Same. * doc/xml/manual/intro.xml: Same. * doc/xml/manual/parallel_mode.xml: Same. * doc/xml/manual/status_cxx1998.xml: Same. * doc/xml/manual/containers.xml: Same. * doc/xml/manual/io.xml: Same. * doc/xml/manual/support.xml: Same. * doc/xml/manual/strings.xml: Same. * doc/xml/manual/debug_mode.xml: Same. * doc/xml/manual/extensions.xml: Same. * doc/xml/manual/appendix_contributing.xml: Same. * doc/xml/manual/messages.xml: Same. * doc/xml/manual/test.xml: Same. * doc/xml/manual/abi.xml: Same. * doc/xml/manual/auto_ptr.xml: Same. * doc/xml/manual/parallel_mode.xml: Same. * doc/xml/manual/build_hacking.xml: Same. * doc/xml/manual/evolution.xml: Same. * doc/xml/manual/using.xml: Same. * doc/xml/manual/debug_mode.xml: Same. * doc/xml/manual/extensions.xml: Same. * doc/xml/manual/diagnostics.xml: Same. * doc/xml/manual/algorithms.xml: Same. * doc/html: Regenerate. From-SVN: r149845
108 lines
3.6 KiB
XML
108 lines
3.6 KiB
XML
<?xml version='1.0'?>
|
|
<!DOCTYPE part PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
|
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
|
|
[ ]>
|
|
|
|
<part id="manual.algorithms" xreflabel="Algorithms">
|
|
<?dbhtml filename="algorithms.html"?>
|
|
|
|
<partinfo>
|
|
<keywordset>
|
|
<keyword>
|
|
ISO C++
|
|
</keyword>
|
|
<keyword>
|
|
library
|
|
</keyword>
|
|
<keyword>
|
|
algorithm
|
|
</keyword>
|
|
</keywordset>
|
|
</partinfo>
|
|
|
|
<title>
|
|
Algorithms
|
|
<indexterm><primary>Algorithms</primary></indexterm>
|
|
</title>
|
|
|
|
<preface>
|
|
<title></title>
|
|
<para>
|
|
The neatest accomplishment of the algorithms chapter is that all the
|
|
work is done via iterators, not containers directly. This means two
|
|
important things:
|
|
</para>
|
|
<orderedlist>
|
|
<listitem>
|
|
<para>
|
|
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.
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
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.
|
|
</para>
|
|
</listitem>
|
|
</orderedlist>
|
|
<para>
|
|
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. The use of
|
|
<emphasis>N</emphasis> as a size in the examples is to keep
|
|
things easy to read but probably won't be valid code. You can
|
|
use wrappers such as those described in the <link
|
|
linkend="manual.containers">containers chapter</link> to
|
|
keep real code readable.
|
|
</para>
|
|
<para>
|
|
The single thing that trips people up the most is the definition
|
|
of <emphasis>range</emphasis> used with iterators; the famous
|
|
"past-the-end" rule that everybody loves to hate. The
|
|
<link linkend="manual.iterators">iterators
|
|
chapter</link> of this document has a complete explanation of
|
|
this simple rule that seems to cause so much confusion. Once you
|
|
get <emphasis>range</emphasis> into your head (it's not that
|
|
hard, honest!), then the algorithms are a cakewalk.
|
|
</para>
|
|
</preface>
|
|
|
|
<!-- Chapter 01 : Non Modifying -->
|
|
|
|
<!-- Chapter 02 : Mutating -->
|
|
<chapter id="manual.algorithms.mutating" xreflabel="Mutating">
|
|
<title>Mutating</title>
|
|
|
|
<sect1 id="algorithms.mutating.swap" xreflabel="swap">
|
|
<title><function>swap</function></title>
|
|
|
|
<sect2 id="algorithms.swap.specializations" xreflabel="Specializations">
|
|
<title>Specializations</title>
|
|
|
|
<para>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.
|
|
</para>
|
|
<para>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.
|
|
</para>
|
|
|
|
</sect2>
|
|
</sect1>
|
|
</chapter>
|
|
|
|
<!-- Chapter 03 : Sorting -->
|
|
|
|
</part>
|