2008-02-11 01:01:33 +01:00
|
|
|
<?xml version='1.0'?>
|
2010-02-25 02:22:57 +01:00
|
|
|
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
|
|
|
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
|
2008-02-11 01:01:33 +01:00
|
|
|
[ ]>
|
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
<chapter id="std.util" xreflabel="Utilities">
|
2008-02-11 01:01:33 +01:00
|
|
|
<?dbhtml filename="utilities.html"?>
|
2010-02-25 02:22:57 +01:00
|
|
|
|
|
|
|
<chapterinfo>
|
2008-02-11 01:01:33 +01:00
|
|
|
<keywordset>
|
|
|
|
<keyword>
|
|
|
|
ISO C++
|
|
|
|
</keyword>
|
|
|
|
<keyword>
|
|
|
|
library
|
|
|
|
</keyword>
|
|
|
|
</keywordset>
|
2010-02-25 02:22:57 +01:00
|
|
|
</chapterinfo>
|
2008-02-11 01:01:33 +01:00
|
|
|
|
2009-04-15 05:11:37 +02:00
|
|
|
<title>
|
|
|
|
Utilities
|
|
|
|
<indexterm><primary>Utilities</primary></indexterm>
|
|
|
|
</title>
|
2008-02-11 01:01:33 +01:00
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
<!-- Section 01 : Functors -->
|
|
|
|
<section id="std.util.functors" xreflabel="Functors">
|
2009-04-16 01:26:59 +02:00
|
|
|
<?dbhtml filename="functors.html"?>
|
2008-02-11 01:01:33 +01:00
|
|
|
<title>Functors</title>
|
|
|
|
<para>If you don't know what functors are, you're not alone. Many people
|
|
|
|
get slightly the wrong idea. In the interest of not reinventing
|
|
|
|
the wheel, we will refer you to the introduction to the functor
|
2010-02-25 02:22:57 +01:00
|
|
|
concept written by SGI as chapter of their STL, in
|
2008-02-11 01:01:33 +01:00
|
|
|
<ulink url="http://www.sgi.com/tech/stl/functors.html">their
|
|
|
|
http://www.sgi.com/tech/stl/functors.html</ulink>.
|
|
|
|
</para>
|
2010-02-25 02:22:57 +01:00
|
|
|
</section>
|
2008-02-11 01:01:33 +01:00
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
<!-- Section 02 : Pairs -->
|
|
|
|
<section id="std.util.pairs" xreflabel="Pairs">
|
2009-04-16 01:26:59 +02:00
|
|
|
<?dbhtml filename="pairs.html"?>
|
2008-02-11 01:01:33 +01:00
|
|
|
<title>Pairs</title>
|
|
|
|
<para>The <code>pair<T1,T2></code> is a simple and handy way to
|
|
|
|
carry around a pair of objects. One is of type T1, and another of
|
|
|
|
type T2; they may be the same type, but you don't get anything
|
|
|
|
extra if they are. The two members can be accessed directly, as
|
|
|
|
<code>.first</code> and <code>.second</code>.
|
|
|
|
</para>
|
|
|
|
<para>Construction is simple. The default ctor initializes each member
|
|
|
|
with its respective default ctor. The other simple ctor,
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
pair (const T1& x, const T2& y);
|
|
|
|
</programlisting>
|
|
|
|
<para>does what you think it does, <code>first</code> getting <code>x</code>
|
|
|
|
and <code>second</code> getting <code>y</code>.
|
|
|
|
</para>
|
|
|
|
<para>There is a copy constructor, but it requires that your compiler
|
|
|
|
handle member function templates:
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
template <class U, class V> pair (const pair<U,V>& p);
|
|
|
|
</programlisting>
|
|
|
|
<para>The compiler will convert as necessary from U to T1 and from
|
|
|
|
V to T2 in order to perform the respective initializations.
|
|
|
|
</para>
|
|
|
|
<para>The comparison operators are done for you. Equality
|
|
|
|
of two <code>pair<T1,T2></code>s is defined as both <code>first</code>
|
|
|
|
members comparing equal and both <code>second</code> members comparing
|
|
|
|
equal; this simply delegates responsibility to the respective
|
|
|
|
<code>operator==</code> functions (for types like MyClass) or builtin
|
|
|
|
comparisons (for types like int, char, etc).
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The less-than operator is a bit odd the first time you see it. It
|
|
|
|
is defined as evaluating to:
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
x.first < y.first ||
|
2010-02-25 02:22:57 +01:00
|
|
|
( !(y.first < x.first) && x.second < y.second )
|
2008-02-11 01:01:33 +01:00
|
|
|
</programlisting>
|
|
|
|
<para>The other operators are not defined using the <code>rel_ops</code>
|
|
|
|
functions above, but their semantics are the same.
|
|
|
|
</para>
|
|
|
|
<para>Finally, there is a template function called <function>make_pair</function>
|
|
|
|
that takes two references-to-const objects and returns an
|
|
|
|
instance of a pair instantiated on their respective types:
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
pair<int,MyClass> p = make_pair(4,myobject);
|
|
|
|
</programlisting>
|
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
</section>
|
2008-02-11 01:01:33 +01:00
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
<!-- Section 03 : Memory -->
|
|
|
|
<section id="std.util.memory" xreflabel="Memory">
|
2009-04-16 01:26:59 +02:00
|
|
|
<?dbhtml filename="memory.html"?>
|
2008-02-11 01:01:33 +01:00
|
|
|
<title>Memory</title>
|
|
|
|
<para>
|
|
|
|
Memory contains three general areas. First, function and operator
|
|
|
|
calls via <function>new</function> and <function>delete</function>
|
|
|
|
operator or member function calls. Second, allocation via
|
|
|
|
<classname>allocator</classname>. And finally, smart pointer and
|
|
|
|
intelligent pointer abstractions.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<!-- Section 01 : allocator -->
|
2010-02-25 02:22:57 +01:00
|
|
|
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
|
2008-02-11 01:01:33 +01:00
|
|
|
parse="xml" href="allocator.xml">
|
|
|
|
</xi:include>
|
|
|
|
|
|
|
|
<!-- Section 02 : auto_ptr -->
|
2010-02-25 02:22:57 +01:00
|
|
|
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
|
2008-02-11 01:01:33 +01:00
|
|
|
parse="xml" href="auto_ptr.xml">
|
|
|
|
</xi:include>
|
|
|
|
|
|
|
|
<!-- Section 03 : shared_ptr -->
|
2010-02-25 02:22:57 +01:00
|
|
|
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
|
2008-02-11 01:01:33 +01:00
|
|
|
parse="xml" href="shared_ptr.xml">
|
|
|
|
</xi:include>
|
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
</section>
|
2008-02-11 01:01:33 +01:00
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
<!-- Section 04 : Traits -->
|
|
|
|
<section id="std.util.traits" xreflabel="Traits">
|
2009-04-16 01:26:59 +02:00
|
|
|
<?dbhtml filename="traits.html"?>
|
2008-02-11 01:01:33 +01:00
|
|
|
<title>Traits</title>
|
|
|
|
<para>
|
|
|
|
</para>
|
2010-02-25 02:22:57 +01:00
|
|
|
</section>
|
2008-02-11 01:01:33 +01:00
|
|
|
|
2010-02-25 02:22:57 +01:00
|
|
|
</chapter>
|