blob: e155c8c39435a75a94be529a0da634475306df5a [file] [log] [blame]
<chapter xmlns="" version="5.0"
xml:id="std.util" xreflabel="Utilities">
<?dbhtml filename="utilities.html"?>
<keyword>ISO C++</keyword>
<!-- Section 01 : Functors -->
<section xml:id="std.util.functors" xreflabel="Functors"><info><title>Functors</title></info>
<?dbhtml filename="functors.html"?>
<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
concept written by SGI as part of their STL, in
<link xmlns:xlink="" xlink:href="">their</link>.
<!-- Section 02 : Pairs -->
<section xml:id="std.util.pairs" xreflabel="Pairs"><info><title>Pairs</title></info>
<?dbhtml filename="pairs.html"?>
<para>The <code>pair&lt;T1,T2&gt;</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>Construction is simple. The default ctor initializes each member
with its respective default ctor. The other simple ctor,
pair (const T1&amp; x, const T2&amp; y);
<para>does what you think it does, <code>first</code> getting <code>x</code>
and <code>second</code> getting <code>y</code>.
<para>There is a constructor template for copying pairs of other types:
template &lt;class U, class V&gt; pair (const pair&lt;U,V&gt;&amp; p);
<para>The compiler will convert as necessary from U to T1 and from
V to T2 in order to perform the respective initializations.
<para>The comparison operators are done for you. Equality
of two <code>pair&lt;T1,T2&gt;</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).
The less-than operator is a bit odd the first time you see it. It
is defined as evaluating to:
x.first &lt; y.first ||
( !(y.first &lt; x.first) &amp;&amp; x.second &lt; y.second )
<para>The other operators are not defined using the <code>rel_ops</code>
functions above, but their semantics are the same.
<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:
pair&lt;int,MyClass&gt; p = make_pair(4,myobject);
<!-- Section 03 : Memory -->
<section xml:id="std.util.memory" xreflabel="Memory"><info><title>Memory</title></info>
<?dbhtml filename="memory.html"?>
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.
<!-- Section 01 : allocator -->
<xi:include xmlns:xi="" parse="xml" href="allocator.xml">
<!-- Section 02 : auto_ptr -->
<xi:include xmlns:xi="" parse="xml" href="auto_ptr.xml">
<!-- Section 03 : shared_ptr -->
<xi:include xmlns:xi="" parse="xml" href="shared_ptr.xml">
<!-- Section 04 : Traits -->
<section xml:id="std.util.traits" xreflabel="Traits"><info><title>Traits</title></info>
<?dbhtml filename="traits.html"?>