2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
6 <chapter id="std.util" xreflabel="Utilities">
7 <?dbhtml filename="utilities.html"?>
22 <indexterm><primary>Utilities</primary></indexterm>
25 <!-- Section 01 : Functors -->
26 <section id="std.util.functors" xreflabel="Functors">
27 <?dbhtml filename="functors.html"?>
28 <title>Functors</title>
29 <para>If you don't know what functors are, you're not alone. Many people
30 get slightly the wrong idea. In the interest of not reinventing
31 the wheel, we will refer you to the introduction to the functor
32 concept written by SGI as chapter of their STL, in
33 <ulink url="http://www.sgi.com/tech/stl/functors.html">their
34 http://www.sgi.com/tech/stl/functors.html</ulink>.
38 <!-- Section 02 : Pairs -->
39 <section id="std.util.pairs" xreflabel="Pairs">
40 <?dbhtml filename="pairs.html"?>
42 <para>The <code>pair<T1,T2></code> is a simple and handy way to
43 carry around a pair of objects. One is of type T1, and another of
44 type T2; they may be the same type, but you don't get anything
45 extra if they are. The two members can be accessed directly, as
46 <code>.first</code> and <code>.second</code>.
48 <para>Construction is simple. The default ctor initializes each member
49 with its respective default ctor. The other simple ctor,
52 pair (const T1& x, const T2& y);
54 <para>does what you think it does, <code>first</code> getting <code>x</code>
55 and <code>second</code> getting <code>y</code>.
57 <para>There is a copy constructor, but it requires that your compiler
58 handle member function templates:
61 template <class U, class V> pair (const pair<U,V>& p);
63 <para>The compiler will convert as necessary from U to T1 and from
64 V to T2 in order to perform the respective initializations.
66 <para>The comparison operators are done for you. Equality
67 of two <code>pair<T1,T2></code>s is defined as both <code>first</code>
68 members comparing equal and both <code>second</code> members comparing
69 equal; this simply delegates responsibility to the respective
70 <code>operator==</code> functions (for types like MyClass) or builtin
71 comparisons (for types like int, char, etc).
74 The less-than operator is a bit odd the first time you see it. It
75 is defined as evaluating to:
78 x.first < y.first ||
79 ( !(y.first < x.first) && x.second < y.second )
81 <para>The other operators are not defined using the <code>rel_ops</code>
82 functions above, but their semantics are the same.
84 <para>Finally, there is a template function called <function>make_pair</function>
85 that takes two references-to-const objects and returns an
86 instance of a pair instantiated on their respective types:
89 pair<int,MyClass> p = make_pair(4,myobject);
94 <!-- Section 03 : Memory -->
95 <section id="std.util.memory" xreflabel="Memory">
96 <?dbhtml filename="memory.html"?>
99 Memory contains three general areas. First, function and operator
100 calls via <function>new</function> and <function>delete</function>
101 operator or member function calls. Second, allocation via
102 <classname>allocator</classname>. And finally, smart pointer and
103 intelligent pointer abstractions.
106 <!-- Section 01 : allocator -->
107 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
108 parse="xml" href="allocator.xml">
111 <!-- Section 02 : auto_ptr -->
112 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
113 parse="xml" href="auto_ptr.xml">
116 <!-- Section 03 : shared_ptr -->
117 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
118 parse="xml" href="shared_ptr.xml">
123 <!-- Section 04 : Traits -->
124 <section id="std.util.traits" xreflabel="Traits">
125 <?dbhtml filename="traits.html"?>
126 <title>Traits</title>