OSDN Git Service

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