]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/xml/manual/utilities.xml
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / xml / manual / utilities.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE part PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" 
3  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" 
4 [ ]>
5
6 <part id="manual.util" xreflabel="Utilities">
7 <?dbhtml filename="utilities.html"?>
8  
9 <partinfo>
10   <keywordset>
11     <keyword>
12       ISO C++
13     </keyword>
14     <keyword>
15       library
16     </keyword>
17   </keywordset>
18 </partinfo>
19
20 <title>Utilities</title>
21
22 <!-- Chapter 01 : Functors -->
23 <chapter id="manual.util.functors" xreflabel="Functors">
24   <title>Functors</title>
25    <para>If you don't know what functors are, you're not alone.  Many people
26       get slightly the wrong idea.  In the interest of not reinventing
27       the wheel, we will refer you to the introduction to the functor
28       concept written by SGI as part of their STL, in
29       <ulink url="http://www.sgi.com/tech/stl/functors.html">their
30       http://www.sgi.com/tech/stl/functors.html</ulink>.
31    </para>
32 </chapter>
33
34 <!-- Chapter 02 : Pairs -->
35 <chapter id="manual.util.pairs" xreflabel="Pairs">
36   <title>Pairs</title>
37    <para>The <code>pair&lt;T1,T2&gt;</code> is a simple and handy way to
38       carry around a pair of objects.  One is of type T1, and another of
39       type T2; they may be the same type, but you don't get anything
40       extra if they are.  The two members can be accessed directly, as
41       <code>.first</code> and <code>.second</code>.
42    </para>
43    <para>Construction is simple.  The default ctor initializes each member
44       with its respective default ctor.  The other simple ctor,
45    </para>
46    <programlisting>
47     pair (const T1&amp; x, const T2&amp; y);
48    </programlisting>
49    <para>does what you think it does, <code>first</code> getting <code>x</code>
50       and <code>second</code> getting <code>y</code>.
51    </para>
52    <para>There is a copy constructor, but it requires that your compiler
53       handle member function templates:
54    </para>
55    <programlisting>
56     template &lt;class U, class V&gt; pair (const pair&lt;U,V&gt;&amp; p);
57    </programlisting>
58    <para>The compiler will convert as necessary from U to T1 and from
59       V to T2 in order to perform the respective initializations.
60    </para>
61    <para>The comparison operators are done for you.  Equality
62       of two <code>pair&lt;T1,T2&gt;</code>s is defined as both <code>first</code>
63       members comparing equal and both <code>second</code> members comparing
64       equal; this simply delegates responsibility to the respective
65       <code>operator==</code> functions (for types like MyClass) or builtin
66       comparisons (for types like int, char, etc).
67    </para>
68    <para>
69       The less-than operator is a bit odd the first time you see it.  It
70       is defined as evaluating to:
71    </para>
72    <programlisting>
73     x.first  &lt;  y.first  ||
74         ( !(y.first  &lt;  x.first)  &amp;&amp;  x.second  &lt;  y.second )
75    </programlisting>
76    <para>The other operators are not defined using the <code>rel_ops</code>
77       functions above, but their semantics are the same.
78    </para>
79    <para>Finally, there is a template function called <function>make_pair</function>
80       that takes two references-to-const objects and returns an
81       instance of a pair instantiated on their respective types:
82    </para>
83    <programlisting>
84     pair&lt;int,MyClass&gt; p = make_pair(4,myobject);
85    </programlisting>
86
87 </chapter>
88
89 <!-- Chapter 03 : Memory -->
90 <chapter id="manual.util.memory" xreflabel="Memory">
91
92   <title>Memory</title>
93   <para>
94     Memory contains three general areas. First, function and operator
95     calls via <function>new</function> and <function>delete</function>
96     operator or member function calls.  Second, allocation via
97     <classname>allocator</classname>. And finally, smart pointer and
98     intelligent pointer abstractions.
99   </para>
100
101   <!--  Section 01 : allocator -->
102   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" 
103               parse="xml" href="allocator.xml">
104   </xi:include>
105
106   <!--  Section 02 : auto_ptr -->
107   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" 
108               parse="xml" href="auto_ptr.xml">
109   </xi:include>
110
111   <!--  Section 03 : shared_ptr -->
112   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" 
113               parse="xml" href="shared_ptr.xml">
114   </xi:include>
115
116 </chapter>
117
118 <!-- Chapter 04 : Traits -->
119 <chapter id="manual.util.traits" xreflabel="Traits">
120   <title>Traits</title>
121   <para>
122   </para>
123 </chapter>
124
125 </part>