1 <chapter xmlns="http://docbook.org/ns/docbook" version="5.0"
2 xml:id="std.util" xreflabel="Utilities">
3 <?dbhtml filename="utilities.html"?>
7 <indexterm><primary>Utilities</primary></indexterm>
10 <keyword>ISO C++</keyword>
11 <keyword>library</keyword>
17 <!-- Section 01 : Functors -->
18 <section xml:id="std.util.functors" xreflabel="Functors"><info><title>Functors</title></info>
19 <?dbhtml filename="functors.html"?>
21 <para>If you don't know what functors are, you're not alone. Many people
22 get slightly the wrong idea. In the interest of not reinventing
23 the wheel, we will refer you to the introduction to the functor
24 concept written by SGI as part of their STL, in
25 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/functors.html">their
26 https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/functors.html</link>.
30 <!-- Section 02 : Pairs -->
31 <section xml:id="std.util.pairs" xreflabel="Pairs"><info><title>Pairs</title></info>
32 <?dbhtml filename="pairs.html"?>
34 <para>The <code>pair<T1,T2></code> is a simple and handy way to
35 carry around a pair of objects. One is of type T1, and another of
36 type T2; they may be the same type, but you don't get anything
37 extra if they are. The two members can be accessed directly, as
38 <code>.first</code> and <code>.second</code>.
40 <para>Construction is simple. The default ctor initializes each member
41 with its respective default ctor. The other simple ctor,
44 pair (const T1& x, const T2& y);
46 <para>does what you think it does, <code>first</code> getting <code>x</code>
47 and <code>second</code> getting <code>y</code>.
49 <para>There is a constructor template for copying pairs of other types:
52 template <class U, class V> pair (const pair<U,V>& p);
54 <para>The compiler will convert as necessary from U to T1 and from
55 V to T2 in order to perform the respective initializations.
57 <para>The comparison operators are done for you. Equality
58 of two <code>pair<T1,T2></code>s is defined as both <code>first</code>
59 members comparing equal and both <code>second</code> members comparing
60 equal; this simply delegates responsibility to the respective
61 <code>operator==</code> functions (for types like MyClass) or builtin
62 comparisons (for types like int, char, etc).
65 The less-than operator is a bit odd the first time you see it. It
66 is defined as evaluating to:
69 x.first < y.first ||
70 ( !(y.first < x.first) && x.second < y.second )
72 <para>The other operators are not defined using the <code>rel_ops</code>
73 functions above, but their semantics are the same.
75 <para>Finally, there is a template function called <function>make_pair</function>
76 that takes two references-to-const objects and returns an
77 instance of a pair instantiated on their respective types:
80 pair<int,MyClass> p = make_pair(4,myobject);
85 <!-- Section 03 : Memory -->
86 <section xml:id="std.util.memory" xreflabel="Memory"><info><title>Memory</title></info>
87 <?dbhtml filename="memory.html"?>
90 Memory contains three general areas. First, function and operator
91 calls via <function>new</function> and <function>delete</function>
92 operator or member function calls. Second, allocation via
93 <classname>allocator</classname>. And finally, smart pointer and
94 intelligent pointer abstractions.
97 <!-- Section 01 : allocator -->
98 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml" href="allocator.xml">
101 <!-- Section 02 : auto_ptr -->
102 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml" href="auto_ptr.xml">
105 <!-- Section 03 : shared_ptr -->
106 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml" href="shared_ptr.xml">
111 <!-- Section 04 : Traits -->
112 <section xml:id="std.util.traits" xreflabel="Traits"><info><title>Traits</title></info>
113 <?dbhtml filename="traits.html"?>